Spaces:
Runtime error
Runtime error
File size: 5,621 Bytes
7dd02a3 cb9a19a b7194b1 cb31db0 b7194b1 cf8af88 7dd02a3 b7194b1 eed17f4 568d79a c615588 eed17f4 488dba6 eed17f4 488dba6 eed17f4 fc4c293 d9fdd26 488dba6 c615588 eed17f4 c615588 eed17f4 b7194b1 488dba6 c615588 eed17f4 488dba6 d9fdd26 eed17f4 d9fdd26 488dba6 eed17f4 b7194b1 eed17f4 f97c4f5 d9fdd26 6a4410c cb31db0 6a4410c f97c4f5 71cf0ef f97c4f5 71cf0ef f97c4f5 71cf0ef f97c4f5 71cf0ef df8494a f97c4f5 eed17f4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
import os
# π‘οΈ Ensure model is saved before importing anything that loads it
if not os.path.exists("trained_model/config.json"):
print("βοΈ No model found. Initializing and saving EvoTransformer...")
from init_model import initialize_and_save_model
initialize_and_save_model()
else:
print("β
EvoTransformer already initialized.")
import gradio as gr
import random
from inference import generate_response
from logger import log_user_feedback
from dashboard import update_dashboard_plot, evolution_accuracy_plot
from watchdog import retrain_model
from init_model import load_model
# === Load model to extract architecture
model = load_model()
def get_architecture_summary(model):
summary = {
"Layers": getattr(model, "num_layers", "N/A"),
"Attention Heads": getattr(model, "num_heads", "N/A"),
"FFN Dim": getattr(model, "ffn_dim", "N/A"),
"Memory Enabled": getattr(model, "use_memory", "N/A"),
}
return "\n".join(f"{k}: {v}" for k, v in summary.items())
# π² Random examples
examples = [
{
"goal": "Escape from a burning house",
"option1": "Run out through the front door",
"option2": "Hide in the bathroom"
},
{
"goal": "Improve sleep quality",
"option1": "Use phone in bed",
"option2": "Turn off screens 1 hour before bed"
},
{
"goal": "Increase productivity at work",
"option1": "Multitask all day",
"option2": "Use Pomodoro technique"
},
{
"goal": "Lose weight safely",
"option1": "Skip meals",
"option2": "Exercise regularly and eat balanced meals"
},
{
"goal": "Ace an exam",
"option1": "Cram the night before",
"option2": "Study consistently for 2 weeks"
},
]
def load_random_example():
example = random.choice(examples)
return example["goal"], example["option1"], example["option2"]
# π§ Model suggestion UI
evo_output = gr.Textbox(label="π§ EvoTransformer Suggestion")
gpt_output = gr.Textbox(label="π¬ GPT-3.5 Suggestion")
feedback_output = gr.Textbox(visible=False)
def evo_chat(goal, sol1, sol2):
response = generate_response(goal, sol1, sol2)
evo = response.get("evo_suggestion", "Error")
gpt = response.get("gpt_suggestion", "Error")
return evo, gpt
def handle_feedback(goal, sol1, sol2, winner):
try:
log_user_feedback(goal, sol1, sol2, winner)
return "β
Feedback logged. Thank you!"
except Exception as e:
return f"β Failed to log: {e}"
with gr.Blocks(title="EvoTransformer v2.1 β Compare Options and Learn") as demo:
gr.Markdown("""
# π€ EvoTransformer v2.1
*Built Different. Learns Live.*
### 𧬠Why EvoTransformer is Special
Unlike traditional AI models that are fixed once deployed, **EvoTransformer evolves**.
- β
Learns from **real-time feedback**
- β
**Retrains** on your input (every time you click ββ»οΈ Retrainβ)
- β
Tracks its **own architecture and accuracy** as it grows
- β
Competes with **GPT-3.5** on real reasoning tasks
- β
Runs light β only ~13M parameters
This isn't just a chatbot. It's a living AI experiment.
Every interaction makes it smarter. You're shaping it.
---
""")
gr.Markdown("## π§ EvoTransformer v2.1 β Compare Options and Learn")
with gr.Row():
goal_input = gr.Textbox(label="Goal", placeholder="e.g. Escape from house on fire")
with gr.Row():
option1_input = gr.Textbox(label="Option 1", placeholder="e.g. Exit house through main door")
option2_input = gr.Textbox(label="Option 2", placeholder="e.g. Hide under bed")
with gr.Row():
compare_btn = gr.Button("π Compare")
random_btn = gr.Button("π² Load Random Example")
with gr.Row():
evo_output.render()
gpt_output.render()
with gr.Row():
winner_dropdown = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?")
feedback_btn = gr.Button("β
Log Feedback")
feedback_output.render()
compare_btn.click(
fn=evo_chat,
inputs=[goal_input, option1_input, option2_input],
outputs=[evo_output, gpt_output]
)
random_btn.click(
fn=load_random_example,
inputs=[],
outputs=[goal_input, option1_input, option2_input]
)
feedback_btn.click(
fn=handle_feedback,
inputs=[goal_input, option1_input, option2_input, winner_dropdown],
outputs=[feedback_output]
)
# === Define UI components to allow later refresh ===
retrain_status = gr.Textbox(label="Retrain Status")
arch_box = gr.Textbox(label="Model Configuration", value=get_architecture_summary(model), lines=5, interactive=False)
evo_plot = gr.Plot(label="Accuracy per Generation", value=evolution_accuracy_plot())
dashboard_img = gr.Image(value=update_dashboard_plot(), label="Solution Votes")
with gr.Row():
retrain_button = gr.Button("β»οΈ Retrain Evo", variant="primary")
retrain_button.click(
fn=retrain_model,
inputs=[],
outputs=[arch_box, evo_plot, retrain_status],
show_progress=True
)
# === Render inside Accordions ===
with gr.Accordion("𧬠EvoTransformer Architecture", open=False):
arch_box
with gr.Accordion("π Evolution Accuracy Plot", open=False):
evo_plot
with gr.Accordion("π User Feedback Summary", open=False):
dashboard_img
with gr.Accordion("π Retrain Status", open=False):
retrain_status
if __name__ == "__main__":
demo.launch(share=True)
|