File size: 1,551 Bytes
c3483b0
 
 
 
 
582209c
c3483b0
582209c
c3483b0
45427dd
562f2a9
c3483b0
562f2a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddcd17e
582209c
562f2a9
582209c
 
 
45427dd
582209c
c3483b0
45427dd
582209c
562f2a9
c3483b0
 
562f2a9
 
 
3360b16
45427dd
562f2a9
45427dd
c3483b0
da6cf3f
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
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:
        process = subprocess.Popen(
            ["python3", "run_eval.py"],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        )

        log_lines = []
        for line in process.stdout:
            print(line, end='', flush=True)
            log_lines.append(line)

        process.wait()

        if process.returncode != 0:
            return "Evaluation failed. See logs above."

    except Exception as e:
        print("Eval script failed:", e, flush=True)
        return "Evaluation failed. Check logs."

    # Optional shutdown trigger (Spaces-only feature)
    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 run `run_eval.py`. The Space will automatically shut down when complete.")
    
    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)