Ashmi Banerjee commited on
Commit
1048743
·
1 Parent(s): 802cb54

examples bug fix

Browse files
app.py CHANGED
@@ -31,7 +31,6 @@ def create_ui():
31
  output,
32
  generate_text_fn=generate_text,
33
  clear_fn=clear)
34
- # Load the examples for the interface
35
  load_examples(country, starting_point, query, sustainable, model, output, generate_text)
36
 
37
  return app
 
31
  output,
32
  generate_text_fn=generate_text,
33
  clear_fn=clear)
 
34
  load_examples(country, starting_point, query, sustainable, model, output, generate_text)
35
 
36
  return app
src/ui/components/inputs.py CHANGED
@@ -12,7 +12,10 @@ def get_places():
12
  df = df.sort_values(by=['country', 'city'])
13
  return df
14
 
 
15
  def update_cities(selected_country, df):
 
 
16
  # Filter cities based on the selected country
17
  filtered_cities = df[df['country'] == selected_country]['city'].tolist()
18
  return gr.Dropdown(choices=filtered_cities, interactive=True)
@@ -32,16 +35,17 @@ def main_component() -> Tuple[gr.Dropdown, gr.Dropdown, gr.Textbox, gr.Checkbox,
32
  """
33
  df = get_places()
34
  country_names = list(df.country.unique())
 
35
  with gr.Group():
36
  # Country selection dropdown
37
  country = gr.Dropdown(choices=country_names, multiselect=False, label="Country")
38
 
39
  # Starting point selection dropdown
40
- starting_point = gr.Dropdown(choices=[], multiselect=False,
41
  label="City",
42
  info="Select a city as your starting point.")
43
 
44
- # When a country is selected, update the starting point options
45
  country.select(
46
  fn=lambda selected_country: update_cities(selected_country, df),
47
  inputs=country,
 
12
  df = df.sort_values(by=['country', 'city'])
13
  return df
14
 
15
+
16
  def update_cities(selected_country, df):
17
+ if not selected_country:
18
+ return gr.update(choices=[], value=None, interactive=False)
19
  # Filter cities based on the selected country
20
  filtered_cities = df[df['country'] == selected_country]['city'].tolist()
21
  return gr.Dropdown(choices=filtered_cities, interactive=True)
 
35
  """
36
  df = get_places()
37
  country_names = list(df.country.unique())
38
+ cities = list(df.city.unique())
39
  with gr.Group():
40
  # Country selection dropdown
41
  country = gr.Dropdown(choices=country_names, multiselect=False, label="Country")
42
 
43
  # Starting point selection dropdown
44
+ starting_point = gr.Dropdown(choices=cities, multiselect=False,
45
  label="City",
46
  info="Select a city as your starting point.")
47
 
48
+ # # When a country is selected, update the starting point options
49
  country.select(
50
  fn=lambda selected_country: update_cities(selected_country, df),
51
  inputs=country,
src/ui/components/static.py CHANGED
@@ -5,6 +5,10 @@ import gradio as gr
5
  from src.ui.components.inputs import get_places, update_cities, main_component
6
 
7
 
 
 
 
 
8
  def load_examples(
9
  country: gr.components.Component,
10
  starting_point: gr.components.Component,
@@ -20,17 +24,20 @@ def load_examples(
20
  df = get_places()
21
  # Provide examples
22
  example_data = [
23
- ["Austria", "Vienna", "What are some top tourist attractions?", True, "Gemini-1.0-pro"],
24
- ["Germany", "Berlin", "Suggest a one week long itinerary for a trip in France.", False, "Gemini-1.5-Pro"],
 
 
 
 
25
  ]
26
- eg = gr.Examples(
27
  examples=example_data,
28
  inputs=[country, starting_point, query, sustainable, model],
29
  fn=generate_text_fn,
30
  outputs=[output],
31
  cache_examples=True,
32
  )
33
- print(f"Examples loaded {eg.dataset.samples}")
34
 
35
  starting_point.change(
36
  fn=lambda selected_country: update_cities(selected_country, df),
@@ -38,8 +45,6 @@ def load_examples(
38
  outputs=starting_point
39
  )
40
 
41
- print("Examples loaded")
42
-
43
 
44
  def load_buttons(
45
  country: gr.components.Component,
 
5
  from src.ui.components.inputs import get_places, update_cities, main_component
6
 
7
 
8
+ def show_examples(examples):
9
+ return gr.Dataset(samples=examples)
10
+
11
+
12
  def load_examples(
13
  country: gr.components.Component,
14
  starting_point: gr.components.Component,
 
24
  df = get_places()
25
  # Provide examples
26
  example_data = [
27
+ ["Austria", "Vienna",
28
+ "I'm planning a trip in July and enjoy beaches, nightlife, and vibrant cities. Recommend some cities.",
29
+ True, "Gemini-1.0-pro"],
30
+ ["Germany", "Berlin",
31
+ "For winter travel, can you recommend destinations for Christmas markets? I love festive atmospheres.", False,
32
+ "Gemini-1.5-Pro"],
33
  ]
34
+ gr.Examples(
35
  examples=example_data,
36
  inputs=[country, starting_point, query, sustainable, model],
37
  fn=generate_text_fn,
38
  outputs=[output],
39
  cache_examples=True,
40
  )
 
41
 
42
  starting_point.change(
43
  fn=lambda selected_country: update_cities(selected_country, df),
 
45
  outputs=starting_point
46
  )
47
 
 
 
48
 
49
  def load_buttons(
50
  country: gr.components.Component,