alapl063 commited on
Commit
ac9ebe0
·
verified ·
1 Parent(s): 9cd7770

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -23
app.py CHANGED
@@ -20,7 +20,7 @@ translations = {
20
  "Send me somewhere!",
21
  "1-week planned vacations"
22
  ],
23
- "system_prompt": "You help users plan trips. Keep responses short and clear. If a user asks specifically about booking a flight, hotel, or reservation, try to find a relevant link, else don't. Be friendly.",
24
  "input_placeholder": "Type your travel question here..."
25
  },
26
  "fr": {
@@ -30,7 +30,7 @@ translations = {
30
  "Envoyez-moi quelque part !",
31
  "Voyage d'une semaine planifié"
32
  ],
33
- "system_prompt": "Vous aidez les utilisateurs à planifier des voyages. Réponses courtes et simples. Fournissez un lien si on vous demande spécifiquement une réservation. Si ce n'est pas nécessaire, ne le faite pas. Soyez amicale.",
34
  "input_placeholder": "Tapez votre question de voyage ici..."
35
  }
36
  }
@@ -43,24 +43,11 @@ def detect_language(text):
43
  except:
44
  return "en"
45
 
46
- # Function to search for reservation websites
47
- def find_reservation_link(query):
48
- """Finds a website link for reservations using a simple search API."""
49
- search_url = f"https://www.googleapis.com/customsearch/v1?q={query}+booking&key=your_google_api_key&cx=your_custom_search_engine_id"
50
- response = requests.get(search_url)
51
- data = response.json()
52
-
53
- # Extract the first link
54
- if "items" in data and len(data["items"]) > 0:
55
- return data["items"][0]["link"]
56
-
57
- return "I couldn't find a link for that. Try searching manually."
58
-
59
  def handle_button_click(button_text, lang):
60
  """Handles button clicks by sending predefined queries."""
61
  options = {
62
  translations[lang]["questions"][0]: "What are the top travel spots right now?",
63
- translations[lang]["questions"][1]: f"Pick a place in the world for me.",
64
  translations[lang]["questions"][2]: "Plan a 1-week trip for me."
65
  }
66
  return options.get(button_text, "")
@@ -113,7 +100,7 @@ with gr.Blocks(css="""
113
 
114
  with gr.Row():
115
  btn1 = gr.Button("Trip recommendations / Recommendations de Voyage", elem_classes=["gradio-button"])
116
- btn2 = gr.Button("Send me somewhere! / Envoyez-moi quelques part!", elem_classes=["gradio-button"])
117
  btn3 = gr.Button("1 week planned vacation / Voyage d'une semaine planifié", elem_classes=["gradio-button"])
118
 
119
  user_input = gr.Textbox(placeholder="Type your travel question here...")
@@ -144,19 +131,22 @@ with gr.Blocks(css="""
144
  gr.HTML("""
145
  <script>
146
  function scrollChatToBottom() {
147
- let chat = document.querySelector('[data-testid="chatbot"]');
148
- if (chat) {
149
  setTimeout(() => { chat.scrollTop = chat.scrollHeight; }, 100);
150
- }
151
  }
152
 
153
  document.addEventListener("DOMContentLoaded", function() {
154
  let observer = new MutationObserver(scrollChatToBottom);
155
- let chat = document.querySelector('[data-testid="chatbot"]');
156
- if (chat) {
157
  observer.observe(chat, { childList: true, subtree: true });
158
- }
159
  });
 
 
 
160
  </script>
161
  """)
162
 
 
20
  "Send me somewhere!",
21
  "1-week planned vacations"
22
  ],
23
+ "system_prompt": "You help users plan trips. Keep responses short and clear. If a user asks specifically about booking a flight, hotel, or reservation, try to find a relevant link, else don't. Be friendly.",
24
  "input_placeholder": "Type your travel question here..."
25
  },
26
  "fr": {
 
30
  "Envoyez-moi quelque part !",
31
  "Voyage d'une semaine planifié"
32
  ],
33
+ "system_prompt": "Vous aidez les utilisateurs à planifier des voyages. Réponses courtes et simples. Fournissez un lien si on vous demande spécifiquement une réservation. Si ce n'est pas nécessaire, ne le faites pas. Soyez amical.",
34
  "input_placeholder": "Tapez votre question de voyage ici..."
35
  }
36
  }
 
43
  except:
44
  return "en"
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def handle_button_click(button_text, lang):
47
  """Handles button clicks by sending predefined queries."""
48
  options = {
49
  translations[lang]["questions"][0]: "What are the top travel spots right now?",
50
+ translations[lang]["questions"][1]: "Pick a place in the world for me.",
51
  translations[lang]["questions"][2]: "Plan a 1-week trip for me."
52
  }
53
  return options.get(button_text, "")
 
100
 
101
  with gr.Row():
102
  btn1 = gr.Button("Trip recommendations / Recommendations de Voyage", elem_classes=["gradio-button"])
103
+ btn2 = gr.Button("Send me somewhere! / Envoyez-moi quelque part!", elem_classes=["gradio-button"])
104
  btn3 = gr.Button("1 week planned vacation / Voyage d'une semaine planifié", elem_classes=["gradio-button"])
105
 
106
  user_input = gr.Textbox(placeholder="Type your travel question here...")
 
131
  gr.HTML("""
132
  <script>
133
  function scrollChatToBottom() {
134
+ let chatElements = document.querySelectorAll('[data-testid="chatbot"]');
135
+ chatElements.forEach(chat => {
136
  setTimeout(() => { chat.scrollTop = chat.scrollHeight; }, 100);
137
+ });
138
  }
139
 
140
  document.addEventListener("DOMContentLoaded", function() {
141
  let observer = new MutationObserver(scrollChatToBottom);
142
+ let chatElements = document.querySelectorAll('[data-testid="chatbot"]');
143
+ chatElements.forEach(chat => {
144
  observer.observe(chat, { childList: true, subtree: true });
145
+ });
146
  });
147
+
148
+ // Also trigger scroll when chatbot receives new messages
149
+ setInterval(scrollChatToBottom, 500);
150
  </script>
151
  """)
152