HemanM commited on
Commit
d9fdd26
Β·
verified Β·
1 Parent(s): 854864a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -44
app.py CHANGED
@@ -1,62 +1,60 @@
1
- import os
2
-
3
- # Run init_save.py only once if trained_model is empty
4
- if not os.path.exists("trained_model/config.json"):
5
- print("βš™οΈ Reinitializing EvoTransformer model...")
6
- import init_save
7
-
8
-
9
- import os
10
  import gradio as gr
11
- from watchdog import manual_retrain
12
  from inference import generate_response
13
  from logger import log_feedback
14
- from dashboard import display_dashboard
 
15
 
16
- # βœ… Ensure model is initialized
17
- if not os.path.exists("trained_model/config.json"):
18
- print("πŸ“¦ No model found in 'trained_model/'. Initializing...")
19
- exec(open("init_save.py").read())
20
 
21
- print("===== Application Startup at 2025-07-14 12:XX:XX =====")
 
22
 
23
- # βœ… Interface logic
24
  def evo_chat(goal, sol1, sol2):
25
- response = generate_response(goal, sol1, sol2)
26
- return response
 
 
 
27
 
28
- def retrain_model():
29
- success = manual_retrain()
30
- return "βœ… Retrained successfully!" if success else "⚠️ Retrain failed."
31
 
32
- def log_user_feedback(goal, sol1, sol2, correct):
33
- log_feedback(goal, sol1, sol2, correct)
34
- return "βœ… Feedback logged. Thank you!"
35
 
36
- # βœ… UI
37
- with gr.Blocks(title="EvoTransformer v2.1") as demo:
38
- gr.Markdown("### 🧠 EvoTransformer v2.1 – Compare Options and Learn")
39
 
40
  with gr.Row():
41
- goal = gr.Textbox(label="Goal")
 
42
  with gr.Row():
43
- sol1 = gr.Textbox(label="Option 1")
44
- sol2 = gr.Textbox(label="Option 2")
45
-
46
- output = gr.Textbox(label="Model Suggestion")
47
- run_btn = gr.Button("πŸ” Compare")
48
- run_btn.click(fn=evo_chat, inputs=[goal, sol1, sol2], outputs=output)
49
 
50
  with gr.Row():
51
- correct = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
52
- log_btn = gr.Button("βœ… Log Feedback")
53
- log_btn.click(fn=log_user_feedback, inputs=[goal, sol1, sol2, correct], outputs=None)
 
 
 
54
 
55
- with gr.Accordion("πŸ“Š Dashboard", open=False):
56
- display_dashboard()
 
 
 
57
 
58
- retrain_btn = gr.Button("♻️ Retrain Evo")
59
- retrain_status = gr.Textbox(label="Retrain Status")
60
- retrain_btn.click(fn=retrain_model, outputs=retrain_status)
 
 
61
 
62
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
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)