Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,78 @@
|
|
1 |
import gradio as gr
|
2 |
-
import json
|
3 |
-
import pandas as pd
|
4 |
from evo_transformer import EvoTransformer
|
5 |
-
from plots import
|
6 |
-
from diagrams import
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
evo = EvoTransformer()
|
10 |
|
11 |
-
def
|
12 |
-
|
13 |
-
|
14 |
-
history = evo.get_history()
|
15 |
-
final_config = history[-1]
|
16 |
-
eval_result = evo.evaluate()
|
17 |
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
pd.DataFrame(history).to_csv(csv_path, index=False)
|
24 |
with open(json_path, "w") as f:
|
25 |
-
json.dump(
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
return (
|
31 |
-
f"{
|
32 |
-
f"{
|
33 |
-
|
34 |
-
|
35 |
diagram_path,
|
|
|
36 |
csv_path,
|
37 |
json_path
|
38 |
)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
gr.Markdown(""
|
43 |
-
# 🧬 EvoTransformer – Evolving Transformer Architectures
|
44 |
-
Simulate trait mutation and adaptive architecture generation.
|
45 |
-
""")
|
46 |
|
47 |
with gr.Row():
|
48 |
-
|
49 |
-
evolve_btn = gr.Button("
|
50 |
|
51 |
with gr.Row():
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
summary_out = gr.Textbox(label="Current Config Summary", lines=5)
|
56 |
-
|
57 |
-
gr.Markdown("""
|
58 |
-
## 🧬 Evolution History
|
59 |
-
""")
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
with gr.Row():
|
65 |
-
|
66 |
-
|
67 |
|
68 |
evolve_btn.click(
|
69 |
-
fn=
|
70 |
-
inputs=[
|
71 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from evo_transformer import EvoTransformer
|
3 |
+
from plots import plot_radar_chart
|
4 |
+
from diagrams import get_transformer_diagram
|
5 |
+
import pandas as pd
|
6 |
+
import json
|
7 |
+
import tempfile
|
8 |
|
9 |
+
et = EvoTransformer()
|
|
|
10 |
|
11 |
+
def run_evolution(generations):
|
12 |
+
et.reset()
|
13 |
+
et.evolve(generations)
|
|
|
|
|
|
|
14 |
|
15 |
+
final_eval = et.evaluate()
|
16 |
+
csv_path = tempfile.NamedTemporaryFile(delete=False, suffix=".csv").name
|
17 |
+
json_path = tempfile.NamedTemporaryFile(delete=False, suffix=".json").name
|
18 |
|
19 |
+
df = pd.DataFrame(et.get_history())
|
20 |
+
df.to_csv(csv_path, index=False)
|
|
|
21 |
with open(json_path, "w") as f:
|
22 |
+
json.dump(et.get_history(), f)
|
23 |
|
24 |
+
radar_plot = plot_radar_chart(et.config)
|
25 |
+
diagram_path = get_transformer_diagram(et.config)
|
26 |
+
|
27 |
+
history_outputs = [gr.Textbox(label=f"Gen {i+1} Config", value=json.dumps(cfg, indent=2), lines=4) for i, cfg in enumerate(et.get_history())]
|
28 |
|
29 |
return (
|
30 |
+
f"{final_eval['accuracy']*100:.2f}%",
|
31 |
+
f"{final_eval['params']:.2f}M params",
|
32 |
+
json.dumps(et.config, indent=2),
|
33 |
+
radar_plot,
|
34 |
diagram_path,
|
35 |
+
history_outputs,
|
36 |
csv_path,
|
37 |
json_path
|
38 |
)
|
39 |
|
40 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
41 |
+
gr.Markdown("## 🧬 EvoTransformer – Evolving Transformer Architectures")
|
42 |
+
gr.Markdown("Simulate trait mutation and adaptive architecture generation.")
|
|
|
|
|
|
|
43 |
|
44 |
with gr.Row():
|
45 |
+
generations_slider = gr.Slider(1, 10, value=3, label="Number of Generations", step=1)
|
46 |
+
evolve_btn = gr.Button("🧬 Evolve Architecture", variant="primary")
|
47 |
|
48 |
with gr.Row():
|
49 |
+
accuracy_output = gr.Textbox(label="Simulated Accuracy")
|
50 |
+
param_output = gr.Textbox(label="Estimated Parameters")
|
51 |
+
current_config = gr.Textbox(label="Current Config Summary", lines=5)
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
with gr.Column():
|
54 |
+
gr.Markdown("## 🧬 Evolution History")
|
55 |
+
radar_output = gr.Image(label="Final Generation Trait Radar", height=400)
|
56 |
+
diagram_output = gr.Image(label="Illustrative Transformer Structure", height=300)
|
57 |
+
history_group = gr.Group()
|
58 |
|
59 |
with gr.Row():
|
60 |
+
csv_download = gr.File(label="Download CSV History")
|
61 |
+
json_download = gr.File(label="Download JSON History")
|
62 |
|
63 |
evolve_btn.click(
|
64 |
+
fn=run_evolution,
|
65 |
+
inputs=[generations_slider],
|
66 |
+
outputs=[
|
67 |
+
accuracy_output,
|
68 |
+
param_output,
|
69 |
+
current_config,
|
70 |
+
radar_output,
|
71 |
+
diagram_output,
|
72 |
+
history_group,
|
73 |
+
csv_download,
|
74 |
+
json_download,
|
75 |
+
],
|
76 |
)
|
77 |
|
78 |
if __name__ == "__main__":
|