File size: 2,596 Bytes
7dd02a3
 
 
 
 
 
 
 
 
 
 
312dbba
c615588
eed17f4
 
 
923fd6e
eed17f4
 
 
568d79a
c615588
eed17f4
 
 
 
488dba6
eed17f4
 
 
 
 
 
488dba6
eed17f4
d9fdd26
488dba6
c615588
eed17f4
c615588
eed17f4
 
 
 
488dba6
c615588
eed17f4
 
488dba6
d9fdd26
eed17f4
d9fdd26
488dba6
eed17f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9fdd26
 
eed17f4
 
 
488dba6
eed17f4
 
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

import os

# βœ… Check if trained_model/config.json exists, if not, initialize the model
if not os.path.exists("trained_model/config.json"):
    from init_model import initialize_and_save_model
    print("βš™οΈ Reinitializing EvoTransformer model...")
    initialize_and_save_model()



import gradio as gr
from inference import generate_response
from logger import log_user_feedback
from dashboard import update_dashboard_plot
from watchdog import retrain_model

evo_output = gr.Textbox(label="🧠 EvoTransformer Suggestion")
gpt_output = gr.Textbox(label="πŸ’¬ GPT-3.5 Suggestion")
feedback_output = gr.Textbox(visible=False)

def evo_chat(goal, sol1, sol2):
    response = generate_response(goal, sol1, sol2)
    evo = response.get("evo_suggestion", "Error")
    gpt = response.get("gpt_suggestion", "Error")
    return evo, gpt

def handle_feedback(goal, sol1, sol2, winner):
    try:
        log_user_feedback(goal, sol1, sol2, winner)
        return "βœ… Feedback logged. Thank you!"
    except Exception as e:
        return f"❌ Failed to log: {e}"

with gr.Blocks(title="EvoTransformer v2.1 – Compare Options and Learn") as demo:
    gr.Markdown("## 🧠 EvoTransformer v2.1 – Compare Options and Learn")

    with gr.Row():
        goal_input = gr.Textbox(label="Goal", placeholder="e.g. Escape from house on fire")
    with gr.Row():
        option1_input = gr.Textbox(label="Option 1", placeholder="e.g. Exit house through main door")
        option2_input = gr.Textbox(label="Option 2", placeholder="e.g. Hide under bed")

    compare_btn = gr.Button("πŸ” Compare")

    with gr.Row():
        evo_output.render()
        gpt_output.render()

    with gr.Row():
        winner_dropdown = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
        feedback_btn = gr.Button("βœ… Log Feedback")

    feedback_output.render()

    compare_btn.click(
        fn=evo_chat,
        inputs=[goal_input, option1_input, option2_input],
        outputs=[evo_output, gpt_output]
    )

    feedback_btn.click(
        fn=handle_feedback,
        inputs=[goal_input, option1_input, option2_input, winner_dropdown],
        outputs=[feedback_output]
    )

    with gr.Row():
        gr.Markdown("### πŸ“Š Dashboard")
        dashboard_plot = gr.Plot()
        update_dashboard_plot(dashboard_plot)

    with gr.Row():
        retrain_button = gr.Button("♻️ Retrain Evo")
        retrain_status = gr.Textbox(label="Retrain Status")

    retrain_button.click(fn=retrain_model, inputs=[], outputs=[retrain_status])

if __name__ == "__main__":
    demo.launch(share=True)