Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
12 |
from inference import generate_response
|
13 |
from logger import log_feedback
|
14 |
-
from
|
|
|
15 |
|
16 |
-
|
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 |
-
|
|
|
22 |
|
23 |
-
#
|
24 |
def evo_chat(goal, sol1, sol2):
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
def
|
29 |
-
|
30 |
-
return
|
31 |
|
32 |
-
def
|
33 |
-
|
34 |
-
return "β
|
35 |
|
36 |
-
|
37 |
-
|
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 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
-
with gr.
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|