HemanM commited on
Commit
2eed809
Β·
verified Β·
1 Parent(s): e256998

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -52
app.py CHANGED
@@ -1,64 +1,69 @@
1
- # βœ… Enhanced EvoTransformer Gradio App – Vivid, Live, Intelligent
2
 
3
  import gradio as gr
4
- from inference import predict
 
5
 
6
- EXAMPLES = [
7
- [
8
- "Start a fire in a fireplace",
9
- "Put a lit match on dry wood",
10
- "Pour water on logs"
11
- ],
12
- [
13
- "Warm a cup of tea",
14
- "Put it in a microwave",
15
- "Put it in the freezer"
16
- ],
17
- [
18
- "Open a locked door",
19
- "Use a key",
20
- "Look at the door intensely"
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 three inputs."
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
- with gr.Blocks(title="EvoTransformer: Real-Time Reasoning AI") as demo:
37
- gr.Markdown("""
38
- # 🧠 EvoTransformer v2.1 – Commonsense Reasoning in Action
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
- with gr.Row():
44
- goal = gr.Textbox(label="Goal", placeholder="e.g., Heat up food")
45
- with gr.Row():
46
- sol1 = gr.Textbox(label="Solution 1", placeholder="e.g., Use a microwave")
47
- sol2 = gr.Textbox(label="Solution 2", placeholder="e.g., Put it in the fridge")
48
- out = gr.Markdown()
49
 
50
- submit = gr.Button("Let Evo Decide")
51
- submit.click(fn=compare, inputs=[goal, sol1, sol2], outputs=out)
52
 
53
- gr.Markdown("### πŸ” Try These Examples:")
54
- gr.Examples(
55
- examples=EXAMPLES,
56
- inputs=[goal, sol1, sol2],
57
- outputs=[out],
58
- fn=compare,
59
- cache_examples=False
60
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- gr.Markdown("---\nMade with ❀️ by Dr. Heman Mohabeer β€” EvoTransformer is not just code. It's evolution.")
 
 
 
 
63
 
64
- demo.launch()
 
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()