Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,69 @@
|
|
1 |
-
# β
|
2 |
|
3 |
import gradio as gr
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
[
|
23 |
-
"Charge a phone",
|
24 |
-
"Plug it into a charger",
|
25 |
-
"Place it on a glass table"
|
26 |
-
]
|
27 |
-
]
|
28 |
|
29 |
def compare(goal, sol1, sol2):
|
30 |
if not goal.strip() or not sol1.strip() or not sol2.strip():
|
31 |
-
return "β οΈ Please provide all
|
32 |
-
result = predict(goal, sol1, sol2)
|
33 |
-
explanation = f"β
EvoTransformer believes **{result}** is the better choice for the goal \"{goal}\"."
|
34 |
-
return explanation
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
Trained on the PIQA dataset. Designed to **choose the most logical solution** between two options.
|
40 |
-
EvoTransformer runs lean β no big GPUs required β and still delivers intelligent behavior.
|
41 |
-
""")
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
sol2 = gr.Textbox(label="Solution 2", placeholder="e.g., Put it in the fridge")
|
48 |
-
out = gr.Markdown()
|
49 |
|
50 |
-
|
51 |
-
submit.click(fn=compare, inputs=[goal, sol1, sol2], outputs=out)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
|
|
1 |
+
# β
Evo Showcase Mode: Full Gradio App with GPT-3.5 Comparison
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import openai
|
5 |
+
from inference import predict as evo_predict
|
6 |
|
7 |
+
# π SET YOUR GPT-3.5 API KEY HERE
|
8 |
+
openai.api_key = "sk-..." # You must insert your OpenAI API key
|
9 |
+
|
10 |
+
def gpt_predict(prompt):
|
11 |
+
try:
|
12 |
+
system_msg = "You're a commonsense reasoning assistant. Given a goal and two options, pick the better one. Only say: Solution 1 or Solution 2."
|
13 |
+
completion = openai.ChatCompletion.create(
|
14 |
+
model="gpt-3.5-turbo",
|
15 |
+
messages=[
|
16 |
+
{"role": "system", "content": system_msg},
|
17 |
+
{"role": "user", "content": prompt}
|
18 |
+
]
|
19 |
+
)
|
20 |
+
return completion["choices"][0]["message"]["content"].strip()
|
21 |
+
except Exception as e:
|
22 |
+
return f"GPT Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def compare(goal, sol1, sol2):
|
25 |
if not goal.strip() or not sol1.strip() or not sol2.strip():
|
26 |
+
return "β οΈ Please provide all inputs.", "", ""
|
|
|
|
|
|
|
27 |
|
28 |
+
prompt = f"Goal: {goal}\nSolution 1: {sol1}\nSolution 2: {sol2}\nWhich is better?"
|
29 |
+
evo = evo_predict(goal, sol1, sol2)
|
30 |
+
gpt = gpt_predict(prompt)
|
|
|
|
|
|
|
31 |
|
32 |
+
if evo == gpt:
|
33 |
+
verdict = "β
Evo agrees with GPT-3.5"
|
34 |
+
else:
|
35 |
+
verdict = "βοΈ Evo disagrees with GPT-3.5 β explore why."
|
|
|
|
|
36 |
|
37 |
+
return f"π§ Evo: {evo}", f"π€ GPT-3.5: {gpt}", verdict
|
|
|
38 |
|
39 |
+
examples = [
|
40 |
+
["Start a fire", "Use a match", "Pour water"],
|
41 |
+
["Warm up food", "Use microwave", "Put it in fridge"],
|
42 |
+
["Charge a phone", "Plug it in", "Put it on grass"],
|
43 |
+
["Get rid of bad smell", "Open window", "Close door"],
|
44 |
+
]
|
45 |
+
|
46 |
+
demo = gr.Interface(
|
47 |
+
fn=compare,
|
48 |
+
inputs=[
|
49 |
+
gr.Textbox(label="Goal"),
|
50 |
+
gr.Textbox(label="Solution 1"),
|
51 |
+
gr.Textbox(label="Solution 2"),
|
52 |
+
],
|
53 |
+
outputs=[
|
54 |
+
gr.Textbox(label="EvoTransformer Response"),
|
55 |
+
gr.Textbox(label="GPT-3.5 Response"),
|
56 |
+
gr.Textbox(label="Verdict")
|
57 |
+
],
|
58 |
+
title="βοΈ Evo vs GPT-3.5 β Real-Time Commonsense Showdown",
|
59 |
+
description="""
|
60 |
+
π§ EvoTransformer v2.1 β PIQA Accuracy: 69.7% (vs GPT-3.5 β 81%)
|
61 |
+
13M Parameters β’ Fully Scratch-Trained β’ Leans Smart
|
62 |
|
63 |
+
This live app shows Evo's answer side-by-side with GPT-3.5. Try it and witness evolution.
|
64 |
+
""",
|
65 |
+
examples=examples,
|
66 |
+
theme="default"
|
67 |
+
)
|
68 |
|
69 |
+
demo.launch()
|