Spaces:
Sleeping
Sleeping
File size: 2,408 Bytes
ce7f881 2ad7d0e 76d9193 ce7f881 2ad7d0e ce7f881 76d9193 ce7f881 76d9193 ce7f881 118680e ce7f881 118680e 2ad7d0e ce7f881 2ad7d0e ce7f881 76d9193 ce7f881 76d9193 ce7f881 2ad7d0e 118680e |
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 |
# app.py
import gradio as gr
import matplotlib.pyplot as plt
import pandas as pd
import io
from evo_transformer import EvoTransformer
def run_evolution(generations):
evo = EvoTransformer()
evo.evolve(generations)
history = evo.get_history()
final_eval = evo.evaluate()
df = pd.DataFrame(history)
df_display = df.copy()
df_display["memory"] = df_display["memory"].apply(lambda x: "Enabled" if x else "Disabled")
# Radar chart
last_config = history[-1]
traits = ["layers", "attention_heads", "ffn_dim", "dropout", "memory"]
values = [last_config["layers"], last_config["attention_heads"],
last_config["ffn_dim"]/100, last_config["dropout"]*10, int(last_config["memory"])*10]
fig, ax = plt.subplots(figsize=(6,6), subplot_kw=dict(polar=True))
angles = [n / float(len(traits)) * 2 * 3.14159 for n in range(len(traits))]
values += values[:1]
angles += angles[:1]
ax.plot(angles, values, linewidth=2)
ax.fill(angles, values, alpha=0.3)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(traits)
ax.set_title("Final Architecture Traits", size=15)
# File downloads
csv_file = io.StringIO(evo.export_csv())
json_file = io.StringIO(evo.export_json())
return (
df_display,
final_eval["accuracy"],
final_eval["params"],
fig,
("evo_history.csv", csv_file.getvalue()),
("evo_history.json", json_file.getvalue())
)
with gr.Blocks(title="EvoTransformer Demo") as demo:
gr.Markdown("# 🧬 EvoTransformer Live Demo")
gr.Markdown("This demo evolves a Transformer architecture and displays how traits change over generations.")
with gr.Row():
generations = gr.Slider(1, 10, value=5, step=1, label="Generations")
run_btn = gr.Button("Evolve Now 🚀")
with gr.Row():
acc = gr.Number(label="Estimated Accuracy")
params = gr.Number(label="Estimated Params (M)")
table = gr.Dataframe(label="Evolution History", wrap=True)
plot = gr.Plot(label="Final Architecture (Radar Chart)")
with gr.Row():
csv_dl = gr.File(label="Download CSV", file_types=[".csv"], interactive=True)
json_dl = gr.File(label="Download JSON", file_types=[".json"], interactive=True)
run_btn.click(fn=run_evolution, inputs=generations, outputs=[table, acc, params, plot, csv_dl, json_dl])
demo.launch()
|