Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from src.chatbot import RestaurantChatbot
|
3 |
|
4 |
-
chatbot = RestaurantChatbot()
|
|
|
5 |
|
6 |
-
def respond(user_message, history):
|
7 |
response, retrieved_docs = chatbot.answer(user_message)
|
8 |
|
9 |
-
|
10 |
if retrieved_docs:
|
11 |
-
doc
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
else:
|
22 |
bot_response += "- Không tìm thấy nhà hàng phù hợp."
|
23 |
|
24 |
-
|
25 |
|
26 |
-
with gr.Blocks(
|
27 |
-
|
28 |
-
|
29 |
-
margin: 0 !important;
|
30 |
-
padding: 0 !important;
|
31 |
-
}
|
32 |
-
.chat-wrapper {
|
33 |
-
height: 100%;
|
34 |
-
display: flex;
|
35 |
-
flex-direction: column;
|
36 |
-
}
|
37 |
-
.chat-interface {
|
38 |
-
flex: 1;
|
39 |
-
display: flex;
|
40 |
-
flex-direction: column;
|
41 |
-
}
|
42 |
-
""") as demo:
|
43 |
-
with gr.Column(elem_classes=["chat-wrapper"]):
|
44 |
-
gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(), elem_classes=["chat-interface"])
|
45 |
|
46 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from src.chatbot import RestaurantChatbot
|
3 |
|
4 |
+
chatbot = RestaurantChatbot()
|
5 |
+
chat_history = []
|
6 |
|
7 |
+
def respond(user_message, history):
|
8 |
response, retrieved_docs = chatbot.answer(user_message)
|
9 |
|
10 |
+
bot_response = f"{response}\n\n**Nhà hàng gợi ý:**\n"
|
11 |
if retrieved_docs:
|
12 |
+
for doc in retrieved_docs:
|
13 |
+
bot_response += (
|
14 |
+
f"- **{doc['name']} ({doc['cuisine']})**\n"
|
15 |
+
f" - Món ăn: {', '.join(doc['dishes'])}\n"
|
16 |
+
f" - Giá: {doc['price_range']}\n"
|
17 |
+
f" - Khoảng cách: {doc['distance']} km\n"
|
18 |
+
f" - Đánh giá: {doc['rating']}\n"
|
19 |
+
f" - Địa chỉ: {doc['address']}\n"
|
20 |
+
f" - Mô tả: {doc['description']}\n"
|
21 |
+
)
|
22 |
else:
|
23 |
bot_response += "- Không tìm thấy nhà hàng phù hợp."
|
24 |
|
25 |
+
return bot_response
|
26 |
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## Chatbot Gợi ý Quán ăn")
|
29 |
+
chatbot_ui = gr.ChatInterface(fn=respond, chatbot=gr.Chatbot())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
demo.launch()
|