Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,99 +1,54 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
import gradio as gr
|
5 |
-
from inference import predict
|
6 |
-
from logger import log_feedback_to_firebase
|
7 |
-
from watchdog import manual_retrain
|
8 |
-
from dashboard import render_dashboard
|
9 |
-
from openai import OpenAI
|
10 |
from watchdog import manual_retrain
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) # Add this secret in your HF Space
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
f"Which option is better? Reply with only 'Solution 1' or 'Solution 2'."
|
22 |
-
)
|
23 |
-
try:
|
24 |
-
response = client.chat.completions.create(
|
25 |
-
model="gpt-3.5-turbo",
|
26 |
-
messages=[{"role": "user", "content": prompt}],
|
27 |
-
temperature=0
|
28 |
-
)
|
29 |
-
reply = response.choices[0].message.content
|
30 |
-
return "Solution 1" if "1" in reply else "Solution 2"
|
31 |
-
except Exception as e:
|
32 |
-
return f"GPT Error: {str(e)}"
|
33 |
|
34 |
-
def
|
35 |
-
evo = predict(goal, sol1, sol2)
|
36 |
-
gpt = gpt_predict(goal, sol1, sol2)
|
37 |
-
|
38 |
-
if evo == gpt == correct:
|
39 |
-
verdict = "β
Both Evo and GPT-3.5 are correct!"
|
40 |
-
elif evo == correct and gpt != correct:
|
41 |
-
verdict = "π§ Evo got it right. GPT-3.5 missed it."
|
42 |
-
elif gpt == correct and evo != correct:
|
43 |
-
verdict = "π€ GPT-3.5 got it right. Evo missed it."
|
44 |
-
else:
|
45 |
-
verdict = "β Both models got it wrong."
|
46 |
-
|
47 |
-
log_feedback_to_firebase(goal, sol1, sol2, evo, gpt, correct, "from app.py")
|
48 |
-
|
49 |
-
return evo, gpt, verdict
|
50 |
-
|
51 |
-
def trigger_retrain():
|
52 |
success = manual_retrain()
|
53 |
-
return "β
|
54 |
-
|
55 |
-
with gr.Blocks() as demo:
|
56 |
-
with gr.Tab("βοΈ Evo vs GPT-3.5 Showdown"):
|
57 |
-
gr.Markdown("## βοΈ Evo vs GPT-3.5 β Real-Time Commonsense Showdown")
|
58 |
-
gr.Markdown(
|
59 |
-
"> π§ EvoTransformer v2.1 β PIQA Accuracy: 69.7% (vs GPT-3.5 β 81%)\n"
|
60 |
-
"> 13M Parameters β’ Fully Scratch-Trained β’ Leans Smart\n"
|
61 |
-
"> π§ͺ *Note: EvoTransformer is a scratch-built model trained on 1K PIQA examples. It may occasionally misinterpret context or idioms. Thatβs part of its evolution.*"
|
62 |
-
)
|
63 |
-
gr.Markdown(
|
64 |
-
"> π *EvoTransformer is not static. Every time you provide feedback, Evo learns and evolves. Welcome to real-time neural evolution.*"
|
65 |
-
)
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
sol1 = gr.Text(label="Solution 1")
|
71 |
-
sol2 = gr.Text(label="Solution 2")
|
72 |
-
correct = gr.Radio(choices=["Solution 1", "Solution 2"], label="β
Which is actually correct?", value="Solution 1")
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
verdict_out = gr.Text(label="βοΈ Verdict")
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
["Warm up food", "Use microwave", "Put it in fridge", "Solution 1"],
|
85 |
-
["Charge a phone", "Plug it in", "Put it on grass", "Solution 1"],
|
86 |
-
["Get rid of bad smell", "Open window", "Close door", "Solution 1"],
|
87 |
-
]
|
88 |
-
gr.Examples(examples=examples, inputs=[goal, sol1, sol2, correct])
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
-
|
97 |
-
|
|
|
98 |
|
99 |
demo.launch()
|
|
|
1 |
+
import os
|
|
|
|
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
3 |
from watchdog import manual_retrain
|
4 |
+
from inference import generate_response
|
5 |
+
from logger import log_feedback
|
6 |
+
from dashboard import display_dashboard
|
7 |
|
8 |
+
# β
Ensure model is initialized
|
9 |
+
if not os.path.exists("trained_model/config.json"):
|
10 |
+
print("π¦ No model found in 'trained_model/'. Initializing...")
|
11 |
+
exec(open("init_save.py").read())
|
12 |
|
13 |
+
print("===== Application Startup at 2025-07-14 12:XX:XX =====")
|
|
|
14 |
|
15 |
+
# β
Interface logic
|
16 |
+
def evo_chat(goal, sol1, sol2):
|
17 |
+
response = generate_response(goal, sol1, sol2)
|
18 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
def retrain_model():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
success = manual_retrain()
|
22 |
+
return "β
Retrained successfully!" if success else "β οΈ Retrain failed."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
def log_user_feedback(goal, sol1, sol2, correct):
|
25 |
+
log_feedback(goal, sol1, sol2, correct)
|
26 |
+
return "β
Feedback logged. Thank you!"
|
|
|
|
|
|
|
27 |
|
28 |
+
# β
UI
|
29 |
+
with gr.Blocks(title="EvoTransformer v2.1") as demo:
|
30 |
+
gr.Markdown("### π§ EvoTransformer v2.1 β Compare Options and Learn")
|
|
|
31 |
|
32 |
+
with gr.Row():
|
33 |
+
goal = gr.Textbox(label="Goal")
|
34 |
+
with gr.Row():
|
35 |
+
sol1 = gr.Textbox(label="Option 1")
|
36 |
+
sol2 = gr.Textbox(label="Option 2")
|
37 |
|
38 |
+
output = gr.Textbox(label="Model Suggestion")
|
39 |
+
run_btn = gr.Button("π Compare")
|
40 |
+
run_btn.click(fn=evo_chat, inputs=[goal, sol1, sol2], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
with gr.Row():
|
43 |
+
correct = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
|
44 |
+
log_btn = gr.Button("β
Log Feedback")
|
45 |
+
log_btn.click(fn=log_user_feedback, inputs=[goal, sol1, sol2, correct], outputs=None)
|
46 |
|
47 |
+
with gr.Accordion("π Dashboard", open=False):
|
48 |
+
display_dashboard()
|
49 |
|
50 |
+
retrain_btn = gr.Button("β»οΈ Retrain Evo")
|
51 |
+
retrain_status = gr.Textbox(label="Retrain Status")
|
52 |
+
retrain_btn.click(fn=retrain_model, outputs=retrain_status)
|
53 |
|
54 |
demo.launch()
|