HemanM commited on
Commit
cd64e90
·
verified ·
1 Parent(s): 749bc03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -12
app.py CHANGED
@@ -3,15 +3,35 @@
3
  import gradio as gr
4
  from generate import generate_response
5
 
6
- def chat_fn(user_input):
7
- return generate_response(user_input)
8
-
9
- iface = gr.Interface(
10
- fn=chat_fn,
11
- inputs=gr.Textbox(lines=2, placeholder="Ask Evo anything..."),
12
- outputs="text",
13
- title="🧠 EvoDecoder Chatbot",
14
- description="A lightweight, custom-trained GPT-style decoder built from scratch."
15
- )
16
-
17
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()