File size: 1,365 Bytes
4363820
 
 
 
 
 
 
 
 
 
238e50c
 
 
 
 
 
 
 
 
 
4363820
 
 
 
 
c00af9f
e84a8c8
c00af9f
 
 
 
e84a8c8
c00af9f
e84a8c8
 
 
 
 
 
 
c00af9f
 
e84a8c8
 
4363820
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from src.chatbot import RestaurantChatbot

chatbot = RestaurantChatbot()

def respond(user_message, history):
    response, retrieved_docs = chatbot.answer(user_message)

    bot_response = f"{response}\n\n**Nhà hàng gợi ý:**\n"
    if retrieved_docs:
        doc = retrieved_docs[0]
        bot_response += (
            f"- **{doc['name']} ({doc['cuisine']})**\n"
            f"  - Món ăn: {', '.join(doc['dishes'])}\n"
            f"  - Giá: {doc['price_range']}\n"
            f"  - Khoảng cách: {doc['distance']} km\n"
            f"  - Đánh giá: {doc['rating']}\n"
            f"  - Địa chỉ: {doc['address']}\n"
            f"  - Mô tả: {doc['description']}\n"
        )
    else:
        bot_response += "- Không tìm thấy nhà hàng phù hợp."

    return bot_response

with gr.Blocks(css="""
    html, body, #root, .gradio-container {
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .chat-wrapper {
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    .chat-interface {
        flex: 1;
        display: flex;
        flex-direction: column;
    }
""") as demo:
    with gr.Column(elem_classes=["chat-wrapper"]):
        gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(), elem_classes=["chat-interface"])

demo.launch()