Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,7 @@ except Exception as e:
|
|
26 |
exit(1)
|
27 |
|
28 |
def respond(message, history, max_tokens=256, temperature=0.7, top_p=0.9):
|
|
|
29 |
history = history or []
|
30 |
input_text = ""
|
31 |
for user_msg, bot_msg in history:
|
@@ -51,7 +52,7 @@ def respond(message, history, max_tokens=256, temperature=0.7, top_p=0.9):
|
|
51 |
|
52 |
formatted_response = format_response(response)
|
53 |
history.append((message, formatted_response))
|
54 |
-
return
|
55 |
|
56 |
def format_response(response):
|
57 |
diagnosis = extract_diagnosis(response)
|
@@ -86,32 +87,28 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
86 |
temperature = gr.Slider(minimum=0.1, maximum=1.5, value=0.7, label="Температура")
|
87 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="Top-p")
|
88 |
clear_btn = gr.Button("Очистить чат", variant="secondary")
|
89 |
-
state = gr.State(value=[])
|
90 |
|
91 |
-
def submit_message(message,
|
92 |
if not message.strip():
|
93 |
-
return
|
94 |
-
|
95 |
-
return
|
96 |
-
|
97 |
-
def clear_chat():
|
98 |
-
return [], [], ""
|
99 |
|
100 |
submit_btn.click(
|
101 |
fn=submit_message,
|
102 |
-
inputs=[msg,
|
103 |
-
outputs=[chatbot,
|
104 |
queue=True
|
105 |
)
|
106 |
msg.submit(
|
107 |
fn=submit_message,
|
108 |
-
inputs=[msg,
|
109 |
-
outputs=[chatbot,
|
110 |
queue=True
|
111 |
)
|
112 |
clear_btn.click(
|
113 |
-
fn=
|
114 |
-
outputs=[chatbot,
|
115 |
)
|
116 |
|
117 |
if __name__ == "__main__":
|
|
|
26 |
exit(1)
|
27 |
|
28 |
def respond(message, history, max_tokens=256, temperature=0.7, top_p=0.9):
|
29 |
+
# История как список кортежей [(user_msg, bot_msg), ...]
|
30 |
history = history or []
|
31 |
input_text = ""
|
32 |
for user_msg, bot_msg in history:
|
|
|
52 |
|
53 |
formatted_response = format_response(response)
|
54 |
history.append((message, formatted_response))
|
55 |
+
return history
|
56 |
|
57 |
def format_response(response):
|
58 |
diagnosis = extract_diagnosis(response)
|
|
|
87 |
temperature = gr.Slider(minimum=0.1, maximum=1.5, value=0.7, label="Температура")
|
88 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="Top-p")
|
89 |
clear_btn = gr.Button("Очистить чат", variant="secondary")
|
|
|
90 |
|
91 |
+
def submit_message(message, chat_history, max_tokens, temperature, top_p):
|
92 |
if not message.strip():
|
93 |
+
return chat_history, "Пожалуйста, введите сообщение."
|
94 |
+
updated_history = respond(message, chat_history, max_tokens, temperature, top_p)
|
95 |
+
return updated_history, ""
|
|
|
|
|
|
|
96 |
|
97 |
submit_btn.click(
|
98 |
fn=submit_message,
|
99 |
+
inputs=[msg, chatbot, max_tokens, temperature, top_p],
|
100 |
+
outputs=[chatbot, msg],
|
101 |
queue=True
|
102 |
)
|
103 |
msg.submit(
|
104 |
fn=submit_message,
|
105 |
+
inputs=[msg, chatbot, max_tokens, temperature, top_p],
|
106 |
+
outputs=[chatbot, msg],
|
107 |
queue=True
|
108 |
)
|
109 |
clear_btn.click(
|
110 |
+
fn=lambda: ([], ""),
|
111 |
+
outputs=[chatbot, msg]
|
112 |
)
|
113 |
|
114 |
if __name__ == "__main__":
|