Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,13 +59,6 @@ h1, h2 {
|
|
59 |
#chatbox {
|
60 |
height: 500px;
|
61 |
}
|
62 |
-
textarea {
|
63 |
-
font-size: 16px !important;
|
64 |
-
}
|
65 |
-
button {
|
66 |
-
font-size: 16px !important;
|
67 |
-
padding: 8px 16px !important;
|
68 |
-
}
|
69 |
"""
|
70 |
|
71 |
with gr.Blocks(css=custom_css) as demo:
|
@@ -74,18 +67,21 @@ with gr.Blocks(css=custom_css) as demo:
|
|
74 |
|
75 |
chatbot = gr.Chatbot(label="Диалог", elem_id="chatbox")
|
76 |
with gr.Row():
|
77 |
-
msg = gr.Textbox(show_label=False, placeholder="Введите
|
78 |
send = gr.Button("Отправить", scale=1)
|
79 |
clear = gr.Button("🗑 Очистить чат")
|
80 |
|
|
|
81 |
def chat_response(user_message, history):
|
82 |
history = history or []
|
|
|
|
|
83 |
bot_reply = generate_response(user_message)
|
84 |
history.append((user_message, bot_reply))
|
85 |
-
return history, ""
|
86 |
|
87 |
-
send.click(chat_response, [msg, chatbot], [chatbot, msg])
|
88 |
-
msg.submit(chat_response, [msg, chatbot], [chatbot, msg])
|
89 |
clear.click(lambda: ([], ""), None, [chatbot, msg])
|
90 |
|
91 |
|
@@ -106,6 +102,7 @@ async def api_ask(request: Request):
|
|
106 |
answer = generate_response(question)
|
107 |
return {"answer": answer}
|
108 |
|
|
|
109 |
app = gr.mount_gradio_app(app, demo, path="/")
|
110 |
|
111 |
if __name__ == "__main__":
|
|
|
59 |
#chatbox {
|
60 |
height: 500px;
|
61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
"""
|
63 |
|
64 |
with gr.Blocks(css=custom_css) as demo:
|
|
|
67 |
|
68 |
chatbot = gr.Chatbot(label="Диалог", elem_id="chatbox")
|
69 |
with gr.Row():
|
70 |
+
msg = gr.Textbox(show_label=False, placeholder="Введите вопрос...", scale=8)
|
71 |
send = gr.Button("Отправить", scale=1)
|
72 |
clear = gr.Button("🗑 Очистить чат")
|
73 |
|
74 |
+
# Логика чата
|
75 |
def chat_response(user_message, history):
|
76 |
history = history or []
|
77 |
+
if not user_message.strip():
|
78 |
+
return history, "" # если пустой ввод
|
79 |
bot_reply = generate_response(user_message)
|
80 |
history.append((user_message, bot_reply))
|
81 |
+
return history, "" # вернём чат и очистим поле
|
82 |
|
83 |
+
send.click(chat_response, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
84 |
+
msg.submit(chat_response, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
85 |
clear.click(lambda: ([], ""), None, [chatbot, msg])
|
86 |
|
87 |
|
|
|
102 |
answer = generate_response(question)
|
103 |
return {"answer": answer}
|
104 |
|
105 |
+
# Встраиваем Gradio в FastAPI
|
106 |
app = gr.mount_gradio_app(app, demo, path="/")
|
107 |
|
108 |
if __name__ == "__main__":
|