Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,39 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from evo_transformer import EvoTransformer
|
5 |
import pandas as pd
|
6 |
-
import matplotlib.pyplot as plt
|
7 |
-
import tempfile
|
8 |
-
import os
|
9 |
import json
|
|
|
|
|
|
|
10 |
|
11 |
-
# === Initialize Model ===
|
12 |
model = EvoTransformer()
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
tabbox = gr.Textbox(label="Current Config Summary")
|
23 |
-
|
24 |
-
# Dynamic display of evolution history
|
25 |
-
history_display = [gr.Textbox(label=f"Gen {i+1} Config") for i in range(10)]
|
26 |
-
|
27 |
-
# Download buttons
|
28 |
-
csv_btn = gr.File(label="Download CSV History")
|
29 |
-
json_btn = gr.File(label="Download JSON History")
|
30 |
-
|
31 |
-
# === Helper: Create Evolution Radar Plot ===
|
32 |
def evolve_and_display(gens):
|
33 |
try:
|
34 |
model.evolve(generations=gens)
|
@@ -70,36 +75,41 @@ def evolve_and_display(gens):
|
|
70 |
None, None, None
|
71 |
)
|
72 |
|
73 |
-
|
74 |
-
with gr.Blocks(title="EvoTransformer Demo") as demo:
|
75 |
gr.Markdown("# 🧬 EvoTransformer – Evolving Transformer Architectures")
|
76 |
gr.Markdown("Simulate trait mutation and adaptive architecture generation.")
|
77 |
-
with gr.Row():
|
78 |
-
generations.render()
|
79 |
-
evolve_btn.render()
|
80 |
|
81 |
with gr.Row():
|
82 |
-
|
83 |
-
|
84 |
|
85 |
with gr.Row():
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
92 |
|
93 |
with gr.Row():
|
94 |
-
|
95 |
-
|
96 |
|
97 |
evolve_btn.click(
|
98 |
evolve_and_display,
|
99 |
inputs=[generations],
|
100 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
)
|
102 |
|
103 |
-
|
104 |
-
if __name__ == "__main__":
|
105 |
-
demo.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from evo_transformer import EvoTransformer
|
3 |
import pandas as pd
|
|
|
|
|
|
|
4 |
import json
|
5 |
+
import tempfile
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
import numpy as np
|
8 |
|
|
|
9 |
model = EvoTransformer()
|
10 |
|
11 |
+
def plot_radar(history):
|
12 |
+
traits = ["layers", "attention_heads", "ffn_dim", "dropout"]
|
13 |
+
labels = traits
|
14 |
+
last = history[-1]
|
15 |
+
values = [
|
16 |
+
last["layers"] / 12,
|
17 |
+
last["attention_heads"] / 12,
|
18 |
+
last["ffn_dim"] / 2048,
|
19 |
+
last["dropout"] / 0.5,
|
20 |
+
]
|
21 |
+
angles = np.linspace(0, 2 * np.pi, len(traits), endpoint=False).tolist()
|
22 |
+
values += values[:1]
|
23 |
+
angles += angles[:1]
|
24 |
+
|
25 |
+
fig, ax = plt.subplots(figsize=(5,5), subplot_kw=dict(polar=True))
|
26 |
+
ax.plot(angles, values, "o-", linewidth=2)
|
27 |
+
ax.fill(angles, values, alpha=0.25)
|
28 |
+
ax.set_thetagrids(np.degrees(angles[:-1]), labels)
|
29 |
+
ax.set_title("Final Generation Trait Radar")
|
30 |
+
ax.grid(True)
|
31 |
+
|
32 |
+
img_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
33 |
+
plt.savefig(img_path)
|
34 |
+
plt.close(fig)
|
35 |
+
return img_path
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def evolve_and_display(gens):
|
38 |
try:
|
39 |
model.evolve(generations=gens)
|
|
|
75 |
None, None, None
|
76 |
)
|
77 |
|
78 |
+
with gr.Blocks() as demo:
|
|
|
79 |
gr.Markdown("# 🧬 EvoTransformer – Evolving Transformer Architectures")
|
80 |
gr.Markdown("Simulate trait mutation and adaptive architecture generation.")
|
|
|
|
|
|
|
81 |
|
82 |
with gr.Row():
|
83 |
+
generations = gr.Slider(1, 10, value=3, step=1, label="Number of Generations")
|
84 |
+
evolve_btn = gr.Button("🧬 Evolve Architecture")
|
85 |
|
86 |
with gr.Row():
|
87 |
+
acc_out = gr.Text(label="Simulated Accuracy")
|
88 |
+
param_out = gr.Text(label="Estimated Parameters")
|
89 |
|
90 |
+
summary_out = gr.Textbox(label="Current Config Summary", lines=5)
|
91 |
+
|
92 |
+
with gr.Accordion("🧬 Evolution History", open=False):
|
93 |
+
hist_outputs = [gr.Textbox(label=f"Gen {i+1} Config", lines=4) for i in range(10)]
|
94 |
+
|
95 |
+
radar_plot = gr.Image(label="Final Generation Trait Radar")
|
96 |
|
97 |
with gr.Row():
|
98 |
+
csv_out = gr.File(label="Download CSV History")
|
99 |
+
json_out = gr.File(label="Download JSON History")
|
100 |
|
101 |
evolve_btn.click(
|
102 |
evolve_and_display,
|
103 |
inputs=[generations],
|
104 |
+
outputs=[
|
105 |
+
acc_out,
|
106 |
+
param_out,
|
107 |
+
summary_out,
|
108 |
+
*hist_outputs,
|
109 |
+
radar_plot,
|
110 |
+
csv_out,
|
111 |
+
json_out
|
112 |
+
],
|
113 |
)
|
114 |
|
115 |
+
demo.launch()
|
|
|
|