Spaces:
Sleeping
Sleeping
File size: 5,056 Bytes
1622676 4f2bf95 09e6d66 515b961 09e6d66 4f2bf95 5340d71 09e6d66 ec9b863 09e6d66 ec9b863 09e6d66 3eaea0f ec9b863 af12592 09e6d66 ec9b863 09e6d66 d9a17fb af12592 3eaea0f a8387b4 61203b9 09e6d66 a8387b4 09e6d66 a8387b4 61203b9 a8387b4 9344674 61203b9 4f2bf95 61203b9 4096d16 09e6d66 4f2bf95 09e6d66 515b961 4f2bf95 515b961 4f2bf95 515b961 4f2bf95 09e6d66 a8387b4 09e6d66 af12592 a8387b4 ec9b863 a8387b4 09e6d66 4f2bf95 09e6d66 a8387b4 09e6d66 a8387b4 b0ba5ba a8387b4 61203b9 af12592 3eaea0f ec9b863 09e6d66 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
import gradio as gr
from inference import evo_chat_predict, get_model_config, get_gpt_response, load_model
import pandas as pd
import csv
import os
from datetime import datetime
from retrain_from_feedback import train_evo
feedback_log = []
with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; color: #f5f5f5; }") as demo:
with gr.Column():
gr.HTML("""
<div style="padding: 10px; border-radius: 12px; background: #1f1f2e; color: #fff; font-size: 16px; margin-bottom: 12px;">
<b>Why Evo?</b> π Evo is not just another AI. It evolves. It learns from you. It adapts its architecture live based on feedback. No retraining labs, no frozen weights. This is <u>live reasoning meets evolution</u>. <span style="color:#88ffcc">Built to outperform, built to survive.</span>
</div>
""")
with gr.Row():
with gr.Column():
query = gr.Textbox(label="π§ Your Question", placeholder="e.g. What should you do if thereβs a fire?")
option1 = gr.Textbox(label="β Option 1", placeholder="Enter the first option")
option2 = gr.Textbox(label="β Option 2", placeholder="Enter the second option")
feedback = gr.Radio(["Evo", "GPT"], label="π§ Who was better?", info="Optional β fuels evolution", interactive=True)
evo_btn = gr.Button("β‘ Ask Evo", elem_id="evo-btn")
retrain_btn = gr.Button("π Retrain Evo", elem_id="retrain-btn")
clear_btn = gr.Button("π§Ή Clear")
export_btn = gr.Button("π€ Export Feedback CSV")
with gr.Column():
evo_stats = gr.Textbox(label="π Evo Stats", interactive=False)
evo_box = gr.Textbox(label="π§ Evo", interactive=False)
gpt_box = gr.Textbox(label="π€ GPT-3.5", interactive=False)
status_box = gr.Textbox(label="π΅ Status", interactive=False)
convo = gr.Dataframe(
headers=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"],
interactive=False, wrap=True, label="π Conversation History"
)
# π Ask Evo
def ask_evo(q, opt1, opt2, hist, selected):
result = evo_chat_predict(hist, q, [opt1, opt2])
evo_text = f"Answer: {result['answer']} (Confidence: {result['confidence']})\n\nReasoning: {result['reasoning']}"
gpt_text = get_gpt_response(q)
stats = get_model_config()
stats_text = f"Layers: {stats['num_layers']} | Heads: {stats['num_heads']} | FFN: {stats['ffn_dim']} | Memory: {stats['memory_enabled']} | Phase: {stats['phase']} | Accuracy: {stats['accuracy']}"
# Update history
new_row = [q, opt1, opt2, result["answer"], result["confidence"], result["reasoning"], result["context_used"]]
new_row_df = pd.DataFrame([new_row], columns=hist.columns)
updated_df = new_row_df if hist.empty else pd.concat([hist, new_row_df], ignore_index=True)
# Log feedback
if selected in ["Evo", "GPT"]:
feedback_log.append(new_row + [selected, "yes" if selected == "Evo" else "no"])
return evo_text, gpt_text, stats_text, updated_df
# π Retrain Evo
def retrain_evo():
if not feedback_log:
return "β οΈ No feedback data to retrain from."
with open("feedback_log.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["question", "option1", "option2", "answer", "confidence", "reasoning", "context", "user_preference", "evo_was_correct"])
for row in feedback_log:
writer.writerow(row)
train_evo()
load_model()
return f"β
Evo retrained on {len(feedback_log)} entries and reloaded."
# π§Ή Clear UI
def clear_fields():
feedback_log.clear()
return "", "", "", "", "", pd.DataFrame(columns=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
# π€ Export feedback
def log_feedback_to_csv():
if feedback_log:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filepath = f"feedback_{timestamp}.csv"
with open(filepath, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context", "User Pref", "Evo Correct"])
writer.writerows(feedback_log)
return f"β
Feedback exported to {filepath}"
else:
return "β οΈ No feedback to export."
# π Event bindings
evo_btn.click(fn=ask_evo, inputs=[query, option1, option2, convo, feedback], outputs=[evo_box, gpt_box, evo_stats, convo])
retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[status_box])
clear_btn.click(fn=clear_fields, inputs=[], outputs=[query, option1, option2, evo_box, gpt_box, convo])
export_btn.click(fn=log_feedback_to_csv, inputs=[], outputs=[status_box])
if __name__ == "__main__":
demo.launch()
|