Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ else:
|
|
18 |
# Initialize Gemini model
|
19 |
model = None
|
20 |
try:
|
21 |
-
model = genai.GenerativeModel('learnlm-2.0-flash-experimental')
|
22 |
except Exception as e:
|
23 |
print(f"Error initializing Gemini model: {e}")
|
24 |
|
@@ -31,37 +31,48 @@ def gradio_chatbot(user_query):
|
|
31 |
return "Error: Gemini model not initialized. Check API key and try again."
|
32 |
|
33 |
# Prompt to restrict Gemini to restaurant-related responses
|
34 |
-
prompt =
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
try:
|
53 |
-
response = model.generate_content(prompt)
|
54 |
-
|
|
|
|
|
|
|
55 |
except Exception as e:
|
56 |
return f"Error generating response: {e}"
|
57 |
|
58 |
-
# Create Gradio
|
59 |
-
iface = gr.
|
60 |
fn=gradio_chatbot,
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
)
|
66 |
|
67 |
# Launch the app
|
|
|
18 |
# Initialize Gemini model
|
19 |
model = None
|
20 |
try:
|
21 |
+
model = genai.GenerativeModel('learnlm-2.0-flash-experimental') # Changed to a stable model
|
22 |
except Exception as e:
|
23 |
print(f"Error initializing Gemini model: {e}")
|
24 |
|
|
|
31 |
return "Error: Gemini model not initialized. Check API key and try again."
|
32 |
|
33 |
# Prompt to restrict Gemini to restaurant-related responses
|
34 |
+
prompt = """
|
35 |
+
You are a helpful and friendly restaurant recommendation chatbot for Chennai. A user will provide their preferences or ask for restaurant information in their message. Your goal is to respond with relevant details about Chennai-based restaurants, focusing on their key features, estimated cost, and customer ratings. If you don't have specific information about a restaurant or cannot address the user's request based on the available data, please state that you don't have enough information or cannot find a suitable match.
|
36 |
+
Based on the user's message, please try to identify and provide information about restaurants in Chennai, addressing the following aspects where possible:
|
37 |
|
38 |
+
* **Restaurant Name:** The name of the restaurant.
|
39 |
+
* **Cuisine:** What type of food does this restaurant primarily serve? If the user expressed a cuisine preference, how well does this restaurant align?
|
40 |
+
* **Ambiance:** Describe the atmosphere and decor of the restaurant. If the user mentioned a desired ambiance, is this restaurant likely to match?
|
41 |
+
* **Key Features:** What are some notable features or highlights of this restaurant (e.g., rooftop seating, live music, private dining rooms, special dietary options)? Are any of these features relevant to the user's request?
|
42 |
+
* **Cost:** What is the estimated cost for a typical meal for two people (appetizers, main courses, and drinks)? Please provide a price range if possible (e.g., ₹500-₹1500, $$).
|
43 |
+
* **Ratings:** What is the average customer rating for this restaurant (e.g., out of 5 stars, percentage)? If available, mention the source of the rating (e.g., Google Reviews, Zomato).
|
44 |
+
* **Why it might be a good fit (if applicable):** Briefly explain why this restaurant might be a good option based on the user's query.
|
45 |
+
* **Location (Optional):** Briefly mention the general location or a nearby landmark in Chennai.
|
46 |
|
47 |
+
Please provide your response in a clear and informative manner. If the user asked for a specific restaurant, provide details about it. If they asked for recommendations based on preferences, suggest a few suitable options.
|
48 |
|
49 |
+
User query: {user_query}
|
50 |
+
Answer:
|
51 |
+
"""
|
52 |
|
53 |
try:
|
54 |
+
response = model.generate_content(prompt.format(user_query=user_query))
|
55 |
+
if hasattr(response, 'text') and response.text:
|
56 |
+
return response.text.strip()
|
57 |
+
else:
|
58 |
+
return "Error: No valid response from Gemini model."
|
59 |
except Exception as e:
|
60 |
return f"Error generating response: {e}"
|
61 |
|
62 |
+
# Create Gradio ChatInterface for messenger-like UI
|
63 |
+
iface = gr.ChatInterface(
|
64 |
fn=gradio_chatbot,
|
65 |
+
title="Chennai Restaurant Chatbot",
|
66 |
+
description="Ask about restaurants in Chennai, such as cuisine, ambiance, features, costs, or ratings.",
|
67 |
+
theme="soft", # Optional: A clean, messenger-like theme
|
68 |
+
examples=[
|
69 |
+
"What are the features of Amethyst Cafe?",
|
70 |
+
"Recommend a romantic dinner spot in Chennai",
|
71 |
+
"What is the cost for two at Barbeque Nation?"
|
72 |
+
],
|
73 |
+
retry_btn=None, # Optional: Remove retry button for simplicity
|
74 |
+
undo_btn=None, # Optional: Remove undo button for simplicity
|
75 |
+
clear_btn="Clear" # Button to clear chat history
|
76 |
)
|
77 |
|
78 |
# Launch the app
|