HemanM commited on
Commit
a0acc08
·
verified ·
1 Parent(s): 74435ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -1,23 +1,35 @@
1
- # app.py — EvoChat UI with live generation
 
2
  import gradio as gr
3
  from generate import generate_response
4
 
5
- with gr.Blocks(title="EvoChat Lightweight Conversational AI") as app:
6
- gr.Markdown("## 🤖 EvoChat — Trained on 1K samples | EvoDecoder")
7
-
8
- chatbot = gr.Chatbot(label="Chat with Evo")
9
- msg = gr.Textbox(label="Your message", placeholder="Ask something...")
10
- clear = gr.Button("Clear")
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- history = []
 
13
 
14
- def chat_fn(message):
15
- history.append(("User: " + message, None))
16
- response = generate_response(message)
17
- history[-1] = (history[-1][0], response)
18
- return history
19
 
20
- msg.submit(chat_fn, inputs=msg, outputs=chatbot)
21
- clear.click(lambda: [], None, chatbot)
22
 
23
- app.launch()
 
1
+ # app.py — Gradio interface for EvoDecoder Chatbot with full conversation context
2
+
3
  import gradio as gr
4
  from generate import generate_response
5
 
6
+ # Define chat function
7
+ def chat_fn(history, message):
8
+ # Merge all past messages to provide conversation context
9
+ context = ""
10
+ for item in history:
11
+ context += f"User: {item['user']}\nAssistant: {item['assistant']}\n"
12
+ context += f"User: {message}\n"
13
+
14
+ # Generate Evo's reply based on full context
15
+ reply = generate_response(context)
16
+
17
+ # Append the new exchange to history
18
+ history.append({"user": message, "assistant": reply})
19
+ return history, ""
20
+
21
+ # Gradio UI setup
22
+ with gr.Blocks() as demo:
23
+ gr.Markdown("## 🧠 Chat with EvoDecoder — A Lightweight Conversational AI")
24
 
25
+ chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
26
+ state = gr.State([])
27
 
28
+ with gr.Row():
29
+ msg = gr.Textbox(label="Your message", placeholder="Ask Evo anything...")
30
+ send_btn = gr.Button("Send")
 
 
31
 
32
+ send_btn.click(chat_fn, inputs=[state, msg], outputs=[chatbot, msg])
33
+ msg.submit(chat_fn, inputs=[state, msg], outputs=[chatbot, msg]) # Enter key submits too
34
 
35
+ demo.launch()