Spaces:
Sleeping
Sleeping
import gradio as gr | |
from inference import evo_chat_predict | |
import subprocess | |
# Global chat history buffer | |
chat_history = [] | |
# π§ Main chat handler | |
def chat_fn(user_input, option1, option2): | |
global chat_history | |
# Validate input | |
if not user_input or not option1 or not option2: | |
return "Please enter a message and both options.", chat_history | |
options = [option1.strip(), option2.strip()] | |
result = evo_chat_predict(chat_history, user_input, options) | |
# Format Evo reply | |
evo_response = f"**Answer:** {result['answer']} \n**Reasoning:** {result['reasoning']}" | |
chat_history.append(f"User: {user_input}") | |
chat_history.append(f"Evo: {evo_response}") | |
return evo_response, chat_history | |
# π Reset chat history | |
def clear_fn(): | |
global chat_history | |
chat_history = [] | |
return "", "", "", [] | |
# π Trigger Evo retraining | |
def retrain_model(): | |
try: | |
subprocess.run(["python", "retrain_from_feedback.py"], check=True) | |
return "β Evo retrained successfully." | |
except Exception as e: | |
return f"β Retraining failed: {str(e)}" | |
# π§ Gradio UI layout | |
with gr.Blocks(title="EvoRAG β Real-Time Adaptive Reasoning AI") as demo: | |
gr.Markdown("## 𧬠EvoRAG β The Evolving Reasoning AI") | |
gr.Markdown("Ask a question, give two options, and Evo will decide with confidence. Then, retrain it live.") | |
with gr.Row(): | |
with gr.Column(scale=4): | |
user_input = gr.Textbox(label="Your Question", lines=2) | |
option1 = gr.Textbox(label="Option 1") | |
option2 = gr.Textbox(label="Option 2") | |
submit = gr.Button("π§ Ask Evo") | |
clear = gr.Button("π Clear") | |
retrain = gr.Button("π Retrain Evo from Feedback") | |
with gr.Column(scale=6): | |
evo_reply = gr.Markdown() | |
chat_display = gr.HighlightedText(label="Conversation History") | |
submit.click(fn=chat_fn, inputs=[user_input, option1, option2], | |
outputs=[evo_reply, chat_display]) | |
clear.click(fn=clear_fn, inputs=[], outputs=[user_input, option1, option2, chat_display]) | |
retrain.click(fn=retrain_model, inputs=[], outputs=evo_reply) | |
demo.launch() | |