Spaces:
Running
Running
import os | |
# Run init_save.py only once if trained_model is empty | |
if not os.path.exists("trained_model/config.json"): | |
print("βοΈ Reinitializing EvoTransformer model...") | |
import init_save | |
import os | |
import gradio as gr | |
from watchdog import manual_retrain | |
from inference import generate_response | |
from logger import log_feedback | |
from dashboard import display_dashboard | |
# β Ensure model is initialized | |
if not os.path.exists("trained_model/config.json"): | |
print("π¦ No model found in 'trained_model/'. Initializing...") | |
exec(open("init_save.py").read()) | |
print("===== Application Startup at 2025-07-14 12:XX:XX =====") | |
# β Interface logic | |
def evo_chat(goal, sol1, sol2): | |
response = generate_response(goal, sol1, sol2) | |
return response | |
def retrain_model(): | |
success = manual_retrain() | |
return "β Retrained successfully!" if success else "β οΈ Retrain failed." | |
def log_user_feedback(goal, sol1, sol2, correct): | |
log_feedback(goal, sol1, sol2, correct) | |
return "β Feedback logged. Thank you!" | |
# β UI | |
with gr.Blocks(title="EvoTransformer v2.1") as demo: | |
gr.Markdown("### π§ EvoTransformer v2.1 β Compare Options and Learn") | |
with gr.Row(): | |
goal = gr.Textbox(label="Goal") | |
with gr.Row(): | |
sol1 = gr.Textbox(label="Option 1") | |
sol2 = gr.Textbox(label="Option 2") | |
output = gr.Textbox(label="Model Suggestion") | |
run_btn = gr.Button("π Compare") | |
run_btn.click(fn=evo_chat, inputs=[goal, sol1, sol2], outputs=output) | |
with gr.Row(): | |
correct = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?") | |
log_btn = gr.Button("β Log Feedback") | |
log_btn.click(fn=log_user_feedback, inputs=[goal, sol1, sol2, correct], outputs=None) | |
with gr.Accordion("π Dashboard", open=False): | |
display_dashboard() | |
retrain_btn = gr.Button("β»οΈ Retrain Evo") | |
retrain_status = gr.Textbox(label="Retrain Status") | |
retrain_btn.click(fn=retrain_model, outputs=retrain_status) | |
demo.launch() | |