EvoConvo / app.py
HemanM's picture
Update app.py
2474a23 verified
raw
history blame
1.21 kB
# app.py — Final version using Gradio "messages" format
import gradio as gr
from generate import generate_response
# Chat function returning proper messages format
def chat_fn(history, message):
# Build full conversation context from history
context = ""
for msg in history:
context += f"User: {msg['content']}\n" if msg["role"] == "user" else f"Assistant: {msg['content']}\n"
context += f"User: {message}\n"
# Generate reply from Evo
reply = generate_response(context)
# Append user and assistant messages
history.append({"role": "user", "content": message})
history.append({"role": "assistant", "content": reply})
return history, ""
# Launch Gradio app
with gr.Blocks() as demo:
gr.Markdown("## 🧠 Chat with EvoDecoder — Lightweight Conversational AI")
chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
state = gr.State([])
with gr.Row():
msg = gr.Textbox(label="Your message", placeholder="Ask Evo anything...")
send_btn = gr.Button("Send")
send_btn.click(chat_fn, inputs=[state, msg], outputs=[chatbot, msg])
msg.submit(chat_fn, inputs=[state, msg], outputs=[chatbot, msg])
demo.launch()