HemanM commited on
Commit
eed17f4
Β·
verified Β·
1 Parent(s): a457e2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -40
app.py CHANGED
@@ -1,60 +1,69 @@
1
  import gradio as gr
2
- import datetime
3
  from inference import generate_response
4
- from logger import log_feedback
5
- from init_model import initialize_evo_model
6
- from init_save import retrain_model
7
 
8
- print(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====")
 
 
9
 
10
- # Reinitialize EvoTransformer model on startup
11
- initialize_evo_model()
12
-
13
- # Gradio app logic
14
  def evo_chat(goal, sol1, sol2):
15
- if not goal.strip() or not sol1.strip() or not sol2.strip():
16
- return "❌ Please fill all fields.", "", "", "", "", gr.update(visible=False)
17
-
18
- suggestion = generate_response(goal, sol1, sol2)
19
- return "", "", "", suggestion, "", gr.update(visible=True)
20
-
21
- def log_user_feedback(goal, sol1, sol2, winner):
22
- status = log_feedback(goal, sol1, sol2, winner)
23
- return status
24
 
25
- def retrain_evo_model():
26
- success = retrain_model()
27
- return "βœ… Retrained successfully." if success else "⚠️ Retrain failed."
 
 
 
28
 
29
- with gr.Blocks(css=".gradio-container {font-family: 'Segoe UI'; font-size: 16px;}") as demo:
30
  gr.Markdown("## 🧠 EvoTransformer v2.1 – Compare Options and Learn")
31
 
32
  with gr.Row():
33
- goal = gr.Textbox(label="Goal", placeholder="e.g. Escape from house on fire")
34
-
35
  with gr.Row():
36
- sol1 = gr.Textbox(label="Option 1", placeholder="e.g. Exit house through main door")
37
- sol2 = gr.Textbox(label="Option 2", placeholder="e.g. Hide under bed")
 
 
38
 
39
  with gr.Row():
40
- error_box = gr.Textbox(label="Error", visible=False)
41
-
42
- model_suggestion = gr.Textbox(label="Model Suggestion")
43
-
44
- compare_button = gr.Button("πŸ” Compare")
45
- compare_button.click(evo_chat, inputs=[goal, sol1, sol2], outputs=[error_box, sol1, sol2, model_suggestion, goal, compare_button])
46
 
47
  with gr.Row():
48
- winner_choice = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
49
  feedback_btn = gr.Button("βœ… Log Feedback")
50
- feedback_status = gr.Textbox(label="", interactive=False)
51
- feedback_btn.click(log_user_feedback, inputs=[goal, sol1, sol2, winner_choice], outputs=[feedback_status])
52
 
53
- gr.Markdown("## πŸ“Š Dashboard")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  with gr.Row():
55
  retrain_button = gr.Button("♻️ Retrain Evo")
56
- retrain_output = gr.Textbox(label="Retrain Status")
57
- retrain_button.click(retrain_evo_model, outputs=[retrain_output])
 
58
 
59
- # Launch with SSR and shareable link if needed
60
- demo.launch(share=True, server_name="0.0.0.0", server_port=7860, show_error=True, ssr_mode=True)
 
1
  import gradio as gr
 
2
  from inference import generate_response
3
+ from logger import log_user_feedback
4
+ from dashboard import update_dashboard_plot
5
+ from watchdog import retrain_model
6
 
7
+ evo_output = gr.Textbox(label="🧠 EvoTransformer Suggestion")
8
+ gpt_output = gr.Textbox(label="πŸ’¬ GPT-3.5 Suggestion")
9
+ feedback_output = gr.Textbox(visible=False)
10
 
 
 
 
 
11
  def evo_chat(goal, sol1, sol2):
12
+ response = generate_response(goal, sol1, sol2)
13
+ evo = response.get("evo_suggestion", "Error")
14
+ gpt = response.get("gpt_suggestion", "Error")
15
+ return evo, gpt
 
 
 
 
 
16
 
17
+ def handle_feedback(goal, sol1, sol2, winner):
18
+ try:
19
+ log_user_feedback(goal, sol1, sol2, winner)
20
+ return "βœ… Feedback logged. Thank you!"
21
+ except Exception as e:
22
+ return f"❌ Failed to log: {e}"
23
 
24
+ with gr.Blocks(title="EvoTransformer v2.1 – Compare Options and Learn") as demo:
25
  gr.Markdown("## 🧠 EvoTransformer v2.1 – Compare Options and Learn")
26
 
27
  with gr.Row():
28
+ goal_input = gr.Textbox(label="Goal", placeholder="e.g. Escape from house on fire")
 
29
  with gr.Row():
30
+ option1_input = gr.Textbox(label="Option 1", placeholder="e.g. Exit house through main door")
31
+ option2_input = gr.Textbox(label="Option 2", placeholder="e.g. Hide under bed")
32
+
33
+ compare_btn = gr.Button("πŸ” Compare")
34
 
35
  with gr.Row():
36
+ evo_output.render()
37
+ gpt_output.render()
 
 
 
 
38
 
39
  with gr.Row():
40
+ winner_dropdown = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
41
  feedback_btn = gr.Button("βœ… Log Feedback")
 
 
42
 
43
+ feedback_output.render()
44
+
45
+ compare_btn.click(
46
+ fn=evo_chat,
47
+ inputs=[goal_input, option1_input, option2_input],
48
+ outputs=[evo_output, gpt_output]
49
+ )
50
+
51
+ feedback_btn.click(
52
+ fn=handle_feedback,
53
+ inputs=[goal_input, option1_input, option2_input, winner_dropdown],
54
+ outputs=[feedback_output]
55
+ )
56
+
57
+ with gr.Row():
58
+ gr.Markdown("### πŸ“Š Dashboard")
59
+ dashboard_plot = gr.Plot()
60
+ update_dashboard_plot(dashboard_plot)
61
+
62
  with gr.Row():
63
  retrain_button = gr.Button("♻️ Retrain Evo")
64
+ retrain_status = gr.Textbox(label="Retrain Status")
65
+
66
+ retrain_button.click(fn=retrain_model, inputs=[], outputs=[retrain_status])
67
 
68
+ if __name__ == "__main__":
69
+ demo.launch(share=True)