import gradio as gr import spaces import subprocess import requests import datetime import os @spaces.GPU def run_peft_eval(): print("Starting evaluation...", flush=True) try: result = subprocess.run(["python3", "run_eval.py"], capture_output=True, text=True, check=True) print(result.stdout, flush=True) except subprocess.CalledProcessError as e: print("Eval script failed:\n", e.stderr, flush=True) return "Evaluation failed. Check logs." try: shutdown_url = os.environ.get("HF_ENDPOINT_SHUTDOWN") if shutdown_url: print("Triggering shutdown...", flush=True) requests.post(shutdown_url) except Exception as e: print("Shutdown failed:", e, flush=True) return f"PEFT-Bench completed at {datetime.datetime.utcnow():%Y-%m-%d %H:%M UTC}" with gr.Blocks() as demo: gr.Markdown("PEFT-Bench GPU Evaluator") gr.Markdown("Click the button below to start evaluation. The Space will shut down when done.") status = gr.Textbox(label="Status", lines=2) btn = gr.Button("Start Evaluation") btn.click(fn=run_peft_eval, outputs=status) demo.launch(show_error=True)