File size: 1,206 Bytes
2474a23 a0acc08 e557b05 2474a23 a0acc08 2474a23 a0acc08 2474a23 a0acc08 2474a23 a0acc08 2474a23 a0acc08 2474a23 a0acc08 2474a23 e557b05 a0acc08 e557b05 a0acc08 e557b05 a0acc08 2474a23 e557b05 a0acc08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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()
|