File size: 5,069 Bytes
1622676
515b961
09e6d66
 
515b961
09e6d66
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
 
 
 
 
 
4096d16
09e6d66
515b961
09e6d66
515b961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09e6d66
a8387b4
09e6d66
af12592
a8387b4
ec9b863
a8387b4
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
102
103
import gradio as gr
from inference import evo_chat_predict, get_model_config, get_gpt_response
import pandas as pd
import csv
import os
from datetime import datetime

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)

        return evo_text, gpt_text, stats_text, updated_df

    # πŸ” Retrain Evo using retrain.py
    def retrain_evo():
        if not feedback_log:
            return "⚠️ No feedback data to retrain from."

        # Save log to feedback_log.csv in required format
        with open("feedback_log.csv", "w", newline="") as f:
            writer = csv.writer(f)
            writer.writerow(["prompt", "context", "label"])
            for row in feedback_log:
                prompt = row[0]
                context = row[6]  # context_used
                label = 0 if row[3] == row[1] else 1  # 0 if answer == option1 else 1
                writer.writerow([prompt, context, label])

        os.system("python retrain.py")
        return "βœ… Evo retrained from feedback_log.csv."

    # 🧹 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"])
                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()