Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from evo_transformer import EvoTransformer
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
)
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
return (
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
f"**FFN Dimension**: {latest_config['ffn_dim']} \n"
|
| 23 |
-
f"**Dropout**: {latest_config['dropout']} \n"
|
| 24 |
-
f"**Memory**: {latest_config['memory']} \n\n"
|
| 25 |
-
f"### Evaluation\n"
|
| 26 |
-
f"**Simulated Accuracy**: {evaluation['accuracy']} \n"
|
| 27 |
-
f"**Estimated Parameters**: {evaluation['params']}M \n\n"
|
| 28 |
-
f"### Trait History (last {generations} generations)\n"
|
| 29 |
-
f"```\n{history_table}\n```"
|
| 30 |
)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
with gr.Blocks(title="EvoTransformer
|
| 34 |
-
gr.Markdown("# 🧬 EvoTransformer")
|
| 35 |
-
gr.Markdown("
|
| 36 |
-
|
| 37 |
-
with gr.Row():
|
| 38 |
-
generations_slider = gr.Slider(1, 10, value=3, label="Generations to Evolve")
|
| 39 |
-
evolve_btn = gr.Button("Evolve")
|
| 40 |
-
|
| 41 |
-
output_box = gr.Markdown()
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
)
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
# Launch the app
|
| 50 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from evo_transformer import EvoTransformer
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import seaborn as sns
|
| 6 |
|
| 7 |
+
def simulate_evolution(generations):
|
| 8 |
+
model = EvoTransformer()
|
| 9 |
+
model.evolve(generations)
|
| 10 |
+
history = model.get_history()
|
| 11 |
+
|
| 12 |
+
# Evaluation of final model
|
| 13 |
+
final_result = model.evaluate()
|
| 14 |
+
|
| 15 |
+
# Visualization
|
| 16 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
| 17 |
+
df = pd.DataFrame(history)
|
| 18 |
+
sns.lineplot(data=df.drop("memory", axis=1), markers=True, ax=ax)
|
| 19 |
+
ax.set_title("EvoTransformer Trait Evolution")
|
| 20 |
+
ax.set_ylabel("Value")
|
| 21 |
+
ax.set_xlabel("Generation")
|
| 22 |
+
plt.xticks(range(len(df)))
|
| 23 |
+
plt.tight_layout()
|
| 24 |
+
|
| 25 |
return (
|
| 26 |
+
final_result["accuracy"],
|
| 27 |
+
round(final_result["params"], 2),
|
| 28 |
+
fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# UI
|
| 32 |
+
with gr.Blocks(title="EvoTransformer: Adaptive Architecture Evolution") as demo:
|
| 33 |
+
gr.Markdown("# 🧬 EvoTransformer Demo")
|
| 34 |
+
gr.Markdown("Evolving architecture live — inspired by nature. Tune the number of generations below and visualize how traits change during evolution.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
generations = gr.Slider(1, 20, value=5, step=1, label="Number of Generations")
|
| 37 |
+
btn = gr.Button("Evolve EvoTransformer")
|
| 38 |
+
|
| 39 |
+
accuracy = gr.Textbox(label="Estimated Accuracy", interactive=False)
|
| 40 |
+
params = gr.Textbox(label="Estimated Parameter Count (M)", interactive=False)
|
| 41 |
+
plot = gr.Plot(label="Architecture Trait Evolution")
|
| 42 |
+
|
| 43 |
+
btn.click(fn=simulate_evolution, inputs=generations, outputs=[accuracy, params, plot])
|
| 44 |
|
|
|
|
| 45 |
demo.launch()
|