Spaces:
Running
Running
File size: 2,483 Bytes
312dbba d9fdd26 c615588 d9fdd26 923fd6e d9fdd26 568d79a d9fdd26 312dbba d9fdd26 c615588 d9fdd26 e256998 d9fdd26 488dba6 d9fdd26 488dba6 d9fdd26 488dba6 c615588 d9fdd26 c615588 d9fdd26 488dba6 c615588 d9fdd26 488dba6 d9fdd26 488dba6 d9fdd26 488dba6 d9fdd26 |
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 |
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)
|