File size: 2,149 Bytes
2ad7d0e
10054c3
b861e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ad7d0e
b861e8e
 
 
 
 
 
ce7f881
 
b861e8e
 
ce7f881
 
b861e8e
 
2ad7d0e
6842aeb
 
b861e8e
 
 
6842aeb
b861e8e
 
76d9193
ce7f881
b861e8e
 
76d9193
eeda69b
b861e8e
 
 
eeda69b
2ad7d0e
b861e8e
 
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
71
72
73
74
75
76
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()