alapl063 commited on
Commit
635bd95
·
verified ·
1 Parent(s): f305fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -5,7 +5,6 @@ import langdetect
5
  import requests
6
  import random
7
 
8
-
9
  GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")
10
  client = Groq(api_key=GROQ_API_KEY)
11
 
@@ -21,7 +20,6 @@ def find_reservation_link(query):
21
  response = requests.get(search_url)
22
  data = response.json()
23
 
24
- # Extract the first link
25
  if "items" in data and len(data["items"]) > 0:
26
  return data["items"][0]["link"]
27
 
@@ -44,30 +42,25 @@ def chat_with_bot(message, history):
44
  if message in ["Trip recommendations", "Send me somewhere!", "1 week planned vacations"]:
45
  message = handle_button_click(message)
46
 
47
- # Detect language (default to English if detection is uncertain)
48
  language = detect_language(message)
49
 
50
  system_message = {
51
- "en": "You help users plan trips. Keep responses short and clear. If a user asks about specifically booking a flight, hotel, or reservation, try to find a relevant link. Else, don't give a link.",
52
- "fr": "Vous aidez les utilisateurs à planifier des voyages. Réponses courtes et simples. Si un utilisateur demande spécifiquement une réservation d'hôtel ou de vol, essayez de trouver un lien pertinent. Sinon, pas besoin."
53
  }
54
 
55
- # Convert history into Groq-compatible message format
56
  messages = [{"role": "system", "content": system_message[language]}]
57
 
58
  for user_msg, bot_msg in history:
59
  messages.append({"role": "user", "content": user_msg})
60
  messages.append({"role": "assistant", "content": bot_msg})
61
 
62
- # Add the latest user message
63
  messages.append({"role": "user", "content": message})
64
 
65
- # Check if the user is looking for reservations
66
  if any(keyword in message.lower() for keyword in ["book a flight", "hotel reservation", "car rental", "book a room"]):
67
  link = find_reservation_link(message)
68
  return history + [(message, f"Here's a link that might help: {link}")], ""
69
 
70
- # Call Groq's AI model
71
  response = client.chat.completions.create(
72
  model="llama-3.3-70b-versatile",
73
  messages=messages,
@@ -90,10 +83,9 @@ with gr.Blocks(css="""
90
  """) as demo:
91
  gr.Markdown("# 🌍 ***FlightAI - Your Travel Assistant - Votre Assistant de Voyage*** ✈️\n")
92
 
93
- chatbot = gr.Chatbot(type="messages")
94
-
95
  chatbot.value = [
96
- ("", "Hey! I'm FlightAI. Tell me your travel plans or pick a button below!\n\nSalut! Je suis FlightAI. Dis-moi ton projet de voyage ou choisis un bouton ci-dessous!")
97
  ]
98
 
99
  with gr.Row():
@@ -112,4 +104,4 @@ with gr.Blocks(css="""
112
  btn3.click(button_click, inputs=[btn3], outputs=[chatbot, user_input])
113
  user_input.submit(chat_with_bot, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
114
 
115
- demo.launch()
 
5
  import requests
6
  import random
7
 
 
8
  GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")
9
  client = Groq(api_key=GROQ_API_KEY)
10
 
 
20
  response = requests.get(search_url)
21
  data = response.json()
22
 
 
23
  if "items" in data and len(data["items"]) > 0:
24
  return data["items"][0]["link"]
25
 
 
42
  if message in ["Trip recommendations", "Send me somewhere!", "1 week planned vacations"]:
43
  message = handle_button_click(message)
44
 
 
45
  language = detect_language(message)
46
 
47
  system_message = {
48
+ "en": "You help users plan trips. Keep responses short and clear.",
49
+ "fr": "Vous aidez les utilisateurs à planifier des voyages. Réponses courtes et simples."
50
  }
51
 
 
52
  messages = [{"role": "system", "content": system_message[language]}]
53
 
54
  for user_msg, bot_msg in history:
55
  messages.append({"role": "user", "content": user_msg})
56
  messages.append({"role": "assistant", "content": bot_msg})
57
 
 
58
  messages.append({"role": "user", "content": message})
59
 
 
60
  if any(keyword in message.lower() for keyword in ["book a flight", "hotel reservation", "car rental", "book a room"]):
61
  link = find_reservation_link(message)
62
  return history + [(message, f"Here's a link that might help: {link}")], ""
63
 
 
64
  response = client.chat.completions.create(
65
  model="llama-3.3-70b-versatile",
66
  messages=messages,
 
83
  """) as demo:
84
  gr.Markdown("# 🌍 ***FlightAI - Your Travel Assistant - Votre Assistant de Voyage*** ✈️\n")
85
 
86
+ chatbot = gr.Chatbot(type="messages") # ✅ Fixed deprecated warning
 
87
  chatbot.value = [
88
+ {"role": "assistant", "content": "Hey! I'm FlightAI. Tell me your travel plans or pick a button below!\n\nSalut! Je suis FlightAI. Dis-moi ton projet de voyage ou choisis un bouton ci-dessous!"}
89
  ]
90
 
91
  with gr.Row():
 
104
  btn3.click(button_click, inputs=[btn3], outputs=[chatbot, user_input])
105
  user_input.submit(chat_with_bot, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
106
 
107
+ demo.launch()