Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import gradio as gr
|
3 |
+
from evo_transformer import EvoTransformer
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
|
6 |
+
def run_evolution(generations):
|
7 |
+
evo = EvoTransformer()
|
8 |
+
evo.evolve(generations)
|
9 |
+
history = evo.get_history()
|
10 |
+
results = evo.evaluate()
|
11 |
+
|
12 |
+
# Format history for output
|
13 |
+
trait_logs = ""
|
14 |
+
for i, config in enumerate(history):
|
15 |
+
trait_logs += f"Generation {i}: {config}\n"
|
16 |
+
|
17 |
+
# Plot number of attention heads over generations
|
18 |
+
heads = [conf["attention_heads"] for conf in history]
|
19 |
+
layers = [conf["layers"] for conf in history]
|
20 |
+
ffn = [conf["ffn_dim"] for conf in history]
|
21 |
+
|
22 |
+
fig, ax = plt.subplots()
|
23 |
+
ax.plot(range(len(heads)), heads, label="Attention Heads")
|
24 |
+
ax.plot(range(len(layers)), layers, label="Layers")
|
25 |
+
ax.plot(range(len(ffn)), ffn, label="FFN Dim")
|
26 |
+
ax.set_title("Evolution of Traits")
|
27 |
+
ax.set_xlabel("Generation")
|
28 |
+
ax.set_ylabel("Value")
|
29 |
+
ax.legend()
|
30 |
+
|
31 |
+
return trait_logs, results["accuracy"], round(results["params"], 2), fig
|
32 |
+
|
33 |
+
# Gradio UI
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=run_evolution,
|
36 |
+
inputs=gr.Slider(minimum=1, maximum=10, step=1, label="Generations"),
|
37 |
+
outputs=[
|
38 |
+
gr.Textbox(label="Evolution History"),
|
39 |
+
gr.Number(label="Simulated Accuracy"),
|
40 |
+
gr.Number(label="Estimated Parameters (M)"),
|
41 |
+
gr.Plot(label="Trait Evolution Plot"),
|
42 |
+
],
|
43 |
+
title="🧬 EvoTransformer Demo",
|
44 |
+
description="An evolving Transformer that mutates architecture traits during training. Watch the architecture change in real time!"
|
45 |
+
)
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
demo.launch()
|