Spaces:
Running
Running
import gradio as gr | |
import datetime | |
from inference import generate_response | |
from logger import log_feedback | |
from init_model import initialize_evo_model | |
from init_save import retrain_model | |
print(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====") | |
# Reinitialize EvoTransformer model on startup | |
initialize_evo_model() | |
# Gradio app logic | |
def evo_chat(goal, sol1, sol2): | |
if not goal.strip() or not sol1.strip() or not sol2.strip(): | |
return "β Please fill all fields.", "", "", "", "", gr.update(visible=False) | |
suggestion = generate_response(goal, sol1, sol2) | |
return "", "", "", suggestion, "", gr.update(visible=True) | |
def log_user_feedback(goal, sol1, sol2, winner): | |
status = log_feedback(goal, sol1, sol2, winner) | |
return status | |
def retrain_evo_model(): | |
success = retrain_model() | |
return "β Retrained successfully." if success else "β οΈ Retrain failed." | |
with gr.Blocks(css=".gradio-container {font-family: 'Segoe UI'; font-size: 16px;}") as demo: | |
gr.Markdown("## π§ EvoTransformer v2.1 β Compare Options and Learn") | |
with gr.Row(): | |
goal = gr.Textbox(label="Goal", placeholder="e.g. Escape from house on fire") | |
with gr.Row(): | |
sol1 = gr.Textbox(label="Option 1", placeholder="e.g. Exit house through main door") | |
sol2 = gr.Textbox(label="Option 2", placeholder="e.g. Hide under bed") | |
with gr.Row(): | |
error_box = gr.Textbox(label="Error", visible=False) | |
model_suggestion = gr.Textbox(label="Model Suggestion") | |
compare_button = gr.Button("π Compare") | |
compare_button.click(evo_chat, inputs=[goal, sol1, sol2], outputs=[error_box, sol1, sol2, model_suggestion, goal, compare_button]) | |
with gr.Row(): | |
winner_choice = gr.Radio(["Solution 1", "Solution 2"], label="Which was better?") | |
feedback_btn = gr.Button("β Log Feedback") | |
feedback_status = gr.Textbox(label="", interactive=False) | |
feedback_btn.click(log_user_feedback, inputs=[goal, sol1, sol2, winner_choice], outputs=[feedback_status]) | |
gr.Markdown("## π Dashboard") | |
with gr.Row(): | |
retrain_button = gr.Button("β»οΈ Retrain Evo") | |
retrain_output = gr.Textbox(label="Retrain Status") | |
retrain_button.click(retrain_evo_model, outputs=[retrain_output]) | |
# Launch with SSR and shareable link if needed | |
demo.launch(share=True, server_name="0.0.0.0", server_port=7860, show_error=True, ssr_mode=True) | |