m-ric HF staff commited on
Commit
c4979f5
1 Parent(s): 010f68b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -8
app.py CHANGED
@@ -15,12 +15,12 @@ Since this is on foot, walking distances should be kept to a minimum. I'll make
15
  I want to start at Fisherman's Wharf, then head to Ghirardelli Square, followed by the Cable Car Museum, Union Square, Chinatown, and finally Coit Tower, to provide a full day of sightseeing, with a mix of history, culture, and beautiful views.
16
 
17
  Key points: [
18
- {"name": "Fisherman's Wharf", "lat": 37.8081, "lon": -122.4082, "description": "Fisherman's Wharf is a popular tourist destination in San Francisco, featuring Pier 39, the Maritime National Historical Park, and Boudin Bakery. It's a great place to start your day with breakfast and enjoy the sea lions."},
19
  {"name": "Ghirardelli Square", "lat": 37.8094, "lon": -122.4154, "description": "Ghirardelli Square is a historic square in San Francisco, known for its chocolate shop and various boutiques. It's a great place to grab a sweet treat and do some shopping."},
20
  {"name": "Cable Car Museum", "lat": 37.7931, "lon": -122.4058, "description": "The Cable Car Museum is a museum in San Francisco that showcases the history of the city's iconic cable cars. It's a great place to learn about the technology and history behind these unique vehicles."},
21
- {"name": "Union Square", "lat": 37.7873, "lon": -122.4062, "description": "Union Square is a public plaza in San Francisco, known for its shopping, dining, and entertainment options. It's a great place to relax, grab a bite to eat, and do some shopping."},
22
  {"name": "Chinatown", "lat": 37.7937, "lon": -122.4081, "description": "Chinatown is a vibrant neighborhood in San Francisco, known for its Chinese culture, history, and cuisine. It's a great place to explore the streets, try some delicious food, and learn about Chinese culture."},
23
- {"name": "Coit Tower", "lat": 37.8024, "lon": -122.4058, "description": "Coit Tower is a historic tower in San Francisco, known for its panoramic views of the city. It's a great place to end your day, taking in the sights and sounds of the city from above."}
24
  ]
25
  """
26
 
@@ -50,6 +50,28 @@ Key points: [
50
  ]
51
  """
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  def generate_key_points(text):
55
  prompt = f"""
@@ -72,6 +94,7 @@ def generate_key_points(text):
72
 
73
 
74
  def parse_llm_output(output):
 
75
  rationale = "Thought: " + output.split("Key points:")[0]
76
  key_points = output.split("Key points:")[1]
77
  output = key_points.replace(" ", "")
@@ -87,7 +110,6 @@ def create_map_from_markers(dataframe):
87
  tiles="CartoDB Voyager",
88
  )
89
 
90
-
91
  dataframe.apply(
92
  lambda row: folium.CircleMarker(
93
  location=[row["lat"], row["lon"]],
@@ -115,12 +137,20 @@ def run_display(text):
115
  map = create_map_from_markers(dataframe)
116
  return map, rationale
117
 
118
- df_examples = pd.DataFrame.from_dict({"description": [description_loire, description_sf], "output": [output_example_loire, output_example_sf]})
 
 
 
 
 
 
 
 
119
 
120
  def select_example(df, data: gr.SelectData):
121
  row = df.iloc[data.index[0], :]
122
- dataframe, rationale = parse_llm_output(row['output'])
123
- return create_map_from_markers(dataframe), rationale
124
 
125
 
126
  with gr.Blocks(
@@ -146,7 +176,9 @@ with gr.Blocks(
146
 
147
  gr.Markdown("### Examples")
148
  clickable_examples = gr.DataFrame(value=df_examples, height=200)
149
- clickable_examples.select(select_example, clickable_examples, outputs=[map, display_rationale])
 
 
150
 
151
  if __name__ == "__main__":
152
  demo.launch()
 
15
  I want to start at Fisherman's Wharf, then head to Ghirardelli Square, followed by the Cable Car Museum, Union Square, Chinatown, and finally Coit Tower, to provide a full day of sightseeing, with a mix of history, culture, and beautiful views.
16
 
17
  Key points: [
18
+ {"name": "Fisherman's Wharf", "lat": 37.8081, "lon": -122.4082, "description": "Fisherman's Wharf is a popular tourist destination in San Francisco, featuring Pier 39, the Maritime National Historical Park, and Boudin Bakery. Start your day with breakfast and enjoy the sea lions."},
19
  {"name": "Ghirardelli Square", "lat": 37.8094, "lon": -122.4154, "description": "Ghirardelli Square is a historic square in San Francisco, known for its chocolate shop and various boutiques. It's a great place to grab a sweet treat and do some shopping."},
20
  {"name": "Cable Car Museum", "lat": 37.7931, "lon": -122.4058, "description": "The Cable Car Museum is a museum in San Francisco that showcases the history of the city's iconic cable cars. It's a great place to learn about the technology and history behind these unique vehicles."},
21
+ {"name": "Union Square", "lat": 37.7873, "lon": -122.4062, "description": "Union Square is a public plaza in San Francisco, known for its shopping, dining, and entertainment options. Relax, grab a bite to eat, and do some shopping."},
22
  {"name": "Chinatown", "lat": 37.7937, "lon": -122.4081, "description": "Chinatown is a vibrant neighborhood in San Francisco, known for its Chinese culture, history, and cuisine. It's a great place to explore the streets, try some delicious food, and learn about Chinese culture."},
23
+ {"name": "Coit Tower", "lat": 37.8024, "lon": -122.4058, "description": "Coit Tower is a historic tower in San Francisco, known for its panoramic views of the city. You can end your day here, taking in the sights and sounds of the city from above."}
24
  ]
25
  """
26
 
 
50
  ]
51
  """
52
 
53
+ description_aligned = "Show me five cities across Europe that form a perfect line on the map. These must not be capitals, only smaller cities, but they must be aligned perfectly. Do it correctly and I'll tip you $10,000."
54
+ output_example_aligned = """To find five cities that form a perfect line on the map, I will first need to determine a direction for the line. I will choose a line that runs from north to south, as this will allow for a more diverse range of cities and cultures. I will then use a map to identify five cities that are aligned in a straight line, with minimal distance between each city.
55
+
56
+ I have identified the following five cities that form a perfect line on the map, running from north to south:
57
+
58
+ 1. Groningen, Netherlands: Groningen is a vibrant student city in the north of the Netherlands, known for its lively cultural scene and historic center.
59
+ 2. Osnabrück, Germany: Osnabrück is a picturesque city in northwest Germany, known for its medieval center and rich history.
60
+ 3. Erfurt, Germany: Erfurt is a charming city in central Germany, known for its well-preserved medieval center and beautiful gardens.
61
+ 4. Nuremberg, Germany: Nuremberg is a historic city in southern Germany, known for its medieval architecture and rich history.
62
+ 5. Innsbruck, Austria: Innsbruck is a stunning city in the Austrian Alps, known for its beautiful mountain scenery and winter sports.
63
+
64
+ These five cities form a perfect line on the map, running from north to south, and offer a diverse range of cultures and experiences.
65
+
66
+ Key points: [
67
+ {"name": "Groningen, Netherlands", "lat": 53.2192, "lon": 6.5667, "description": "Groningen is a vibrant student city in the north of the Netherlands, known for its lively cultural scene and historic center. The city is home to the University of Groningen, one of the oldest and most respected universities in the country, and has a rich history dating back to the Middle Ages."},
68
+ {"name": "Osnabrück, Germany", "lat": 52.2708, "lon": 8.0431, "description": "Osnabrück is a picturesque city in northwest Germany, known for its medieval center and rich history. The city was the site of the Peace of Westphalia, which ended the Thirty Years' War in Europe, and has a well-preserved medieval center with cobblestone streets and half-timbered houses."},
69
+ {"name": "Erfurt, Germany", "lat": 50.9778, "lon": 11.0278, "description": "Erfurt is a charming city in central Germany, known for its well-preserved medieval center and beautiful gardens. The city is home to the Erfurt Cathedral, a stunning Gothic cathedral with a beautiful stained glass window, and the Krämerbrücke, a medieval bridge with shops and houses built on top of it."},
70
+ {"name": "Nuremberg, Germany", "lat": 49.4500, "lon": 11.0750, "description": "Nuremberg is a historic city in southern Germany, known for its medieval architecture and rich history. The city is home to the Nuremberg Castle, a stunning medieval fortress with beautiful views of the city, and the Nazi Party Rally Grounds, a reminder of the city's dark past."},
71
+ {"name": "Innsbruck, Austria", "lat": 47.2692, "lon": 11.3914, "description": "Innsbruck is a stunning city in the Austrian Alps, known for its beautiful mountain scenery and winter sports. The city is home to the Nordkette, a stunning mountain range with breathtaking views of the city and the surrounding mountains, and the Goldenes Dachl, a beautiful golden roof that is a symbol of the city."}
72
+ ]
73
+ """
74
+
75
 
76
  def generate_key_points(text):
77
  prompt = f"""
 
94
 
95
 
96
  def parse_llm_output(output):
97
+ print(output)
98
  rationale = "Thought: " + output.split("Key points:")[0]
99
  key_points = output.split("Key points:")[1]
100
  output = key_points.replace(" ", "")
 
110
  tiles="CartoDB Voyager",
111
  )
112
 
 
113
  dataframe.apply(
114
  lambda row: folium.CircleMarker(
115
  location=[row["lat"], row["lon"]],
 
137
  map = create_map_from_markers(dataframe)
138
  return map, rationale
139
 
140
+
141
+ df_examples = pd.DataFrame.from_dict(
142
+ [
143
+ {"description": description_loire, "output": output_example_loire},
144
+ {"description": description_sf, "output": output_example_sf},
145
+ {"description": description_aligned, "output": output_example_aligned},
146
+ ]
147
+ )
148
+
149
 
150
  def select_example(df, data: gr.SelectData):
151
  row = df.iloc[data.index[0], :]
152
+ dataframe, rationale = parse_llm_output(row["output"])
153
+ return row["description"], create_map_from_markers(dataframe), rationale
154
 
155
 
156
  with gr.Blocks(
 
176
 
177
  gr.Markdown("### Examples")
178
  clickable_examples = gr.DataFrame(value=df_examples, height=200)
179
+ clickable_examples.select(
180
+ select_example, clickable_examples, outputs=[text, map, display_rationale]
181
+ )
182
 
183
  if __name__ == "__main__":
184
  demo.launch()