File size: 2,578 Bytes
acf354e
394a74f
3dfd005
e8b4e81
394a74f
acf354e
e8b4e81
f3c00ab
78914a2
86bfe51
 
78914a2
e8b4e81
abebb3b
 
86bfe51
3229259
b53506b
 
abebb3b
6714a02
cb8de4a
6714a02
aee5791
b53506b
86bfe51
362cd4e
 
 
 
 
 
 
78914a2
362cd4e
 
 
 
 
78914a2
f3c00ab
 
 
 
 
 
78914a2
6714a02
f3c00ab
 
 
 
 
 
b53506b
f3c00ab
 
b53506b
86bfe51
78914a2
e8b4e81
86bfe51
f3c00ab
78914a2
3229259
e8b4e81
86bfe51
f3c00ab
fba00bc
 
f3c00ab
 
 
 
 
 
 
 
 
86bfe51
e8b4e81
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import gradio as gr
from huggingface_hub import HfApi

HF_TOKEN = os.getenv("HF_TOKEN")
api = HfApi(token=HF_TOKEN)

def scan_spaces_detailed(username: str):
    """
    Scan all Spaces for a user and display metadata in table form.
    Sort all ZeroGPU spaces first.
    """
    try:
        spaces = api.list_spaces(author=username, token=HF_TOKEN)
        if not spaces:
            return [["No Spaces found", "", "", ""]]

        results = []

        for space in spaces:
            try:
                info = api.space_info(space.id, token=HF_TOKEN)
                status = getattr(info, "status", "unknown")
                tags = getattr(info, "tags", [])

                # Determine hardware type
                runtime = getattr(info, "runtime", None)
                if runtime:
                    requested_hw = getattr(runtime, "requested_hardware", None)
                    if requested_hw and requested_hw.lower().startswith("zero"):
                        hardware = "ZeroGPU"
                    else:
                        hardware = "GPU"
                else:
                    hardware_field = getattr(info, "hardware", None)
                    if hardware_field:
                        hardware = "ZeroGPU" if all("cpu" in h.lower() for h in hardware_field) else "GPU"
                    else:
                        hardware = "ZeroGPU" if "cpu" in tags else "GPU"

                results.append([
                    space.id,
                    status,
                    hardware,
                    ", ".join(tags)
                ])

            except Exception as e:
                results.append([
                    space.id,
                    f"Error retrieving info: {e}",
                    "Unknown",
                    ""
                ])

        # Sort ZeroGPU first
        results.sort(key=lambda x: 0 if x[2] == "ZeroGPU" else 1)

        return results

    except Exception as e:
        return [[f"Error: {e}", "", "", ""]]


# Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("## πŸ” Hugging Face Spaces ZeroGPU Scanner (Tabular View)")

    with gr.Row():
        username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
        scan_button = gr.Button("Scan Spaces")

    output_table = gr.Dataframe(
        headers=["Space ID", "Status", "Hardware", "Tags"],
        datatype=["str", "str", "str", "str"],
        interactive=False,
        wrap=True
    )

    scan_button.click(scan_spaces_detailed, inputs=username_input, outputs=output_table)

demo.launch()