|
|
|
|
|
import gradio as gr |
|
from generate import generate_response |
|
|
|
|
|
def chat_fn(history, message): |
|
|
|
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" |
|
|
|
|
|
reply = generate_response(context) |
|
|
|
|
|
history.append({"role": "user", "content": message}) |
|
history.append({"role": "assistant", "content": reply}) |
|
return history, "" |
|
|
|
|
|
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() |
|
|