Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
import pandas as pd | |
from evo_transformer import EvoTransformer | |
from plots import plot_radar | |
from diagrams import draw_transformer_diagram | |
# Initialize EvoTransformer | |
evo = EvoTransformer() | |
def evolve_transformer(generations): | |
evo = EvoTransformer() | |
evo.evolve(generations) | |
history = evo.get_history() | |
final_config = history[-1] | |
eval_result = evo.evaluate() | |
radar_path = plot_radar(final_config) | |
diagram_path = draw_transformer_diagram() | |
csv_path = "history.csv" | |
json_path = "history.json" | |
pd.DataFrame(history).to_csv(csv_path, index=False) | |
with open(json_path, "w") as f: | |
json.dump(history, f, indent=2) | |
# Format config display | |
summary = "\n".join(f"{k}: {v}" for k, v in final_config.items()) | |
return ( | |
f"{eval_result['accuracy']*100:.2f}%", | |
f"{eval_result['params']:.2f}M params", | |
summary, | |
radar_path, | |
diagram_path, | |
csv_path, | |
json_path | |
) | |
# Gradio Interface | |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo: | |
gr.Markdown(""" | |
# 🧬 EvoTransformer – Evolving Transformer Architectures | |
Simulate trait mutation and adaptive architecture generation. | |
""") | |
with gr.Row(): | |
gens = gr.Slider(1, 10, value=3, step=1, label="Number of Generations") | |
evolve_btn = gr.Button("\ud83e\uddec Evolve Architecture") | |
with gr.Row(): | |
acc_out = gr.Textbox(label="Simulated Accuracy") | |
param_out = gr.Textbox(label="Estimated Parameters") | |
summary_out = gr.Textbox(label="Current Config Summary", lines=5) | |
gr.Markdown(""" | |
## 🧬 Evolution History | |
""") | |
radar_img = gr.Image(label="Final Generation Trait Radar") | |
diagram_img = gr.Image(label="Transformer Architecture") | |
with gr.Row(): | |
csv_dl = gr.File(label="Download CSV History") | |
json_dl = gr.File(label="Download JSON History") | |
evolve_btn.click( | |
fn=evolve_transformer, | |
inputs=[gens], | |
outputs=[acc_out, param_out, summary_out, radar_img, diagram_img, csv_dl, json_dl] | |
) | |
if __name__ == "__main__": | |
demo.launch() | |