Update app.py
Browse files
app.py
CHANGED
@@ -3,15 +3,35 @@
|
|
3 |
import gradio as gr
|
4 |
from generate import generate_response
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
)
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import gradio as gr
|
4 |
from generate import generate_response
|
5 |
|
6 |
+
chat_history = []
|
7 |
+
|
8 |
+
def chat(user_input):
|
9 |
+
global chat_history
|
10 |
+
|
11 |
+
# Append user input
|
12 |
+
chat_history.append(f"User: {user_input}")
|
13 |
+
|
14 |
+
# Prepare full conversation context
|
15 |
+
context = "\n".join(chat_history)
|
16 |
+
evo_reply = generate_response(context)
|
17 |
+
|
18 |
+
# Append Evo's response
|
19 |
+
chat_history.append(f"Evo: {evo_reply}")
|
20 |
+
|
21 |
+
# Keep last 10 turns to avoid overlong context
|
22 |
+
if len(chat_history) > 20:
|
23 |
+
chat_history = chat_history[-20:]
|
24 |
+
|
25 |
+
return "\n".join(chat_history)
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("### 🧠 Evo Chat (Stateful Level 2)")
|
29 |
+
chatbot = gr.Textbox(label="Chat History", lines=15, interactive=False)
|
30 |
+
user_input = gr.Textbox(label="Your Message")
|
31 |
+
|
32 |
+
def submit_message(message):
|
33 |
+
return chat(message)
|
34 |
+
|
35 |
+
user_input.submit(submit_message, inputs=user_input, outputs=chatbot)
|
36 |
+
|
37 |
+
demo.launch()
|