Shafaq25 commited on
Commit
c34b1be
Β·
verified Β·
1 Parent(s): c76c926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -33
app.py CHANGED
@@ -9,9 +9,7 @@ weather_api_key = os.getenv("openweather")
9
  openai_api_key = os.getenv("OPENAI_API_KEY")
10
  client = OpenAI(api_key=openai_api_key)
11
 
12
- # -------------------------------
13
- # Fetch Weather Data
14
- # -------------------------------
15
  def get_weather(city_name):
16
  if not city_name.strip():
17
  city_name = "Dubai"
@@ -45,10 +43,7 @@ def get_weather(city_name):
45
  except Exception:
46
  return None
47
 
48
-
49
- # -------------------------------
50
- # Weather Display HTML
51
- # -------------------------------
52
  def format_weather_display(data):
53
  if not data:
54
  return "<div style='text-align:center; color: #e74c3c; font-size: 18px; padding: 40px;'>❌ City not found. Please try again.</div>"
@@ -99,10 +94,7 @@ def format_weather_display(data):
99
  </div>
100
  """
101
 
102
-
103
- # -------------------------------
104
  # Chatbot
105
- # -------------------------------
106
  def travel_chat(msg, history):
107
  messages = [{"role": "system", "content": "You are a helpful travel assistant. Suggest tourist attractions, activities, and travel tips for any city."}]
108
  for h in history:
@@ -123,10 +115,7 @@ def travel_chat(msg, history):
123
  history.append({"role": "assistant", "content": reply})
124
  return history, history
125
 
126
-
127
- # -------------------------------
128
  # Attractions
129
- # -------------------------------
130
  def get_attractions(city, country, temp, weather_desc):
131
  try:
132
  messages = [
@@ -162,7 +151,6 @@ def get_attractions(city, country, temp, weather_desc):
162
  except Exception:
163
  return [("Error", "Could not fetch attractions.")]
164
 
165
-
166
  def format_attraction_card(name, details):
167
  return f"""
168
  <div class='card'>
@@ -171,10 +159,7 @@ def format_attraction_card(name, details):
171
  </div>
172
  """
173
 
174
-
175
- # -------------------------------
176
  # CSS
177
- # -------------------------------
178
  custom_css = """
179
  body, .gradio-container {
180
  background: linear-gradient(135deg, #f5f7fa 0%, #bbdefb 100%) !important;
@@ -246,9 +231,6 @@ body, .gradio-container {
246
  }
247
  """
248
 
249
- # -------------------------------
250
- # Generate Attraction Cards
251
- # -------------------------------
252
  def generate_attraction_cards(city):
253
  weather = get_weather(city)
254
  if not weather:
@@ -262,27 +244,22 @@ def generate_attraction_cards(city):
262
  )
263
  return "<div class='card-grid'>" + "".join(format_attraction_card(name, details) for name, details in attractions) + "</div>"
264
 
265
-
266
- # -------------------------------
267
  # UI
268
- # -------------------------------
269
  def launch_ui():
270
  with gr.Blocks(css=custom_css, title="TripMate AI") as demo:
271
- # Main Title
272
- gr.Markdown("<div id='main-title'>🌍 TripMate AI</div>")
273
 
274
  with gr.Row(equal_height=True):
275
- # Weather section
276
  with gr.Column(scale=1):
277
- gr.Markdown("<div class='section-header'>🌀️ Weather Dashboard</div>")
278
  with gr.Group(elem_classes="content-box"):
279
  city_input = gr.Textbox(label="πŸ™οΈ City Name", value="Dubai")
280
  update_btn = gr.Button("πŸ“ Get Weather Data")
281
  weather_html = gr.HTML()
282
 
283
- # Chatbot section
284
  with gr.Column(scale=1):
285
- gr.Markdown("<div class='section-header'>πŸ€– Travel Assistant</div>")
286
  with gr.Group(elem_classes="content-box"):
287
  chat = gr.Chatbot(height=350, type="messages")
288
  with gr.Row():
@@ -290,8 +267,7 @@ def launch_ui():
290
  ask_btn = gr.Button("Send", scale=1)
291
  state = gr.State([])
292
 
293
- # Attractions section
294
- gr.Markdown("<div class='section-header'>πŸ–οΈ Top Attractions You Can Visit</div>")
295
  attractions_html = gr.HTML()
296
 
297
  def update_all(city):
@@ -306,9 +282,8 @@ def launch_ui():
306
  demo.load(fn=lambda: update_all("Dubai"), inputs=None, outputs=[weather_html, attractions_html])
307
 
308
  # Footer
309
- gr.Markdown("<div class='footer'>Β© 2025 TripMate AI – Your AI-powered travel companion.</div>")
310
 
311
  demo.launch()
312
 
313
-
314
  launch_ui()
 
9
  openai_api_key = os.getenv("OPENAI_API_KEY")
10
  client = OpenAI(api_key=openai_api_key)
11
 
12
+ # Weather fetch
 
 
13
  def get_weather(city_name):
14
  if not city_name.strip():
15
  city_name = "Dubai"
 
43
  except Exception:
44
  return None
45
 
46
+ # Weather display
 
 
 
47
  def format_weather_display(data):
48
  if not data:
49
  return "<div style='text-align:center; color: #e74c3c; font-size: 18px; padding: 40px;'>❌ City not found. Please try again.</div>"
 
94
  </div>
95
  """
96
 
 
 
97
  # Chatbot
 
98
  def travel_chat(msg, history):
99
  messages = [{"role": "system", "content": "You are a helpful travel assistant. Suggest tourist attractions, activities, and travel tips for any city."}]
100
  for h in history:
 
115
  history.append({"role": "assistant", "content": reply})
116
  return history, history
117
 
 
 
118
  # Attractions
 
119
  def get_attractions(city, country, temp, weather_desc):
120
  try:
121
  messages = [
 
151
  except Exception:
152
  return [("Error", "Could not fetch attractions.")]
153
 
 
154
  def format_attraction_card(name, details):
155
  return f"""
156
  <div class='card'>
 
159
  </div>
160
  """
161
 
 
 
162
  # CSS
 
163
  custom_css = """
164
  body, .gradio-container {
165
  background: linear-gradient(135deg, #f5f7fa 0%, #bbdefb 100%) !important;
 
231
  }
232
  """
233
 
 
 
 
234
  def generate_attraction_cards(city):
235
  weather = get_weather(city)
236
  if not weather:
 
244
  )
245
  return "<div class='card-grid'>" + "".join(format_attraction_card(name, details) for name, details in attractions) + "</div>"
246
 
 
 
247
  # UI
 
248
  def launch_ui():
249
  with gr.Blocks(css=custom_css, title="TripMate AI") as demo:
250
+ # Header
251
+ gr.HTML("<div id='main-title'>🌍 TripMate AI</div>")
252
 
253
  with gr.Row(equal_height=True):
 
254
  with gr.Column(scale=1):
255
+ gr.HTML("<div class='section-header'>🌀️ Weather Dashboard</div>")
256
  with gr.Group(elem_classes="content-box"):
257
  city_input = gr.Textbox(label="πŸ™οΈ City Name", value="Dubai")
258
  update_btn = gr.Button("πŸ“ Get Weather Data")
259
  weather_html = gr.HTML()
260
 
 
261
  with gr.Column(scale=1):
262
+ gr.HTML("<div class='section-header'>πŸ€– Travel Assistant</div>")
263
  with gr.Group(elem_classes="content-box"):
264
  chat = gr.Chatbot(height=350, type="messages")
265
  with gr.Row():
 
267
  ask_btn = gr.Button("Send", scale=1)
268
  state = gr.State([])
269
 
270
+ gr.HTML("<div class='section-header'>πŸ–οΈ Top Attractions You Can Visit</div>")
 
271
  attractions_html = gr.HTML()
272
 
273
  def update_all(city):
 
282
  demo.load(fn=lambda: update_all("Dubai"), inputs=None, outputs=[weather_html, attractions_html])
283
 
284
  # Footer
285
+ gr.HTML("<div class='footer'>Β© 2025 TripMate AI – Your AI-powered travel companion.</div>")
286
 
287
  demo.launch()
288
 
 
289
  launch_ui()