Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,15 @@ from huggingface_hub import HfApi
|
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
api = HfApi(token=HF_TOKEN)
|
| 7 |
|
| 8 |
-
|
| 9 |
def scan_spaces_detailed(username: str):
|
| 10 |
"""
|
| 11 |
-
Scan all Spaces for a user and
|
|
|
|
| 12 |
"""
|
| 13 |
try:
|
| 14 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
| 15 |
if not spaces:
|
| 16 |
-
return [
|
| 17 |
|
| 18 |
results = []
|
| 19 |
|
|
@@ -23,7 +23,7 @@ def scan_spaces_detailed(username: str):
|
|
| 23 |
status = getattr(info, "status", "unknown")
|
| 24 |
tags = getattr(info, "tags", [])
|
| 25 |
|
| 26 |
-
#
|
| 27 |
runtime = getattr(info, "runtime", None)
|
| 28 |
if runtime:
|
| 29 |
requested_hw = getattr(runtime, "requested_hardware", None)
|
|
@@ -56,32 +56,20 @@ def scan_spaces_detailed(username: str):
|
|
| 56 |
# Sort ZeroGPU first
|
| 57 |
results.sort(key=lambda x: 0 if x[2] == "ZeroGPU" else 1)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
hardware_values = sorted(list({r[2] for r in results}))
|
| 61 |
-
return results, ["All"] + hardware_values
|
| 62 |
|
| 63 |
except Exception as e:
|
| 64 |
-
return [[f"Error: {e}", "", "", ""]]
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def filter_table(rows, selected_hw):
|
| 68 |
-
"""Filter the table by hardware locally (no API call)."""
|
| 69 |
-
if not rows or selected_hw == "All":
|
| 70 |
-
return rows
|
| 71 |
-
return [r for r in rows if r[2] == selected_hw]
|
| 72 |
|
| 73 |
|
| 74 |
# Gradio UI
|
| 75 |
with gr.Blocks() as demo:
|
| 76 |
-
gr.Markdown("##
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
|
| 80 |
scan_button = gr.Button("Scan Spaces")
|
| 81 |
|
| 82 |
-
with gr.Row():
|
| 83 |
-
filter_hw = gr.Dropdown(label="Filter by Hardware", choices=["All"], value="All", interactive=True)
|
| 84 |
-
|
| 85 |
output_table = gr.Dataframe(
|
| 86 |
headers=["Space ID", "Status", "Hardware", "Tags"],
|
| 87 |
datatype=["str", "str", "str", "str"],
|
|
@@ -89,18 +77,6 @@ with gr.Blocks() as demo:
|
|
| 89 |
wrap=True
|
| 90 |
)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
scan_event = scan_button.click(
|
| 94 |
-
fn=scan_spaces_detailed,
|
| 95 |
-
inputs=username_input,
|
| 96 |
-
outputs=[output_table, filter_hw]
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
# When filter changes: re-filter table without re-calling API
|
| 100 |
-
filter_hw.change(
|
| 101 |
-
fn=filter_table,
|
| 102 |
-
inputs=[output_table, filter_hw],
|
| 103 |
-
outputs=output_table
|
| 104 |
-
)
|
| 105 |
|
| 106 |
demo.launch()
|
|
|
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
api = HfApi(token=HF_TOKEN)
|
| 7 |
|
|
|
|
| 8 |
def scan_spaces_detailed(username: str):
|
| 9 |
"""
|
| 10 |
+
Scan all Spaces for a user and display metadata in table form.
|
| 11 |
+
Sort all ZeroGPU spaces first.
|
| 12 |
"""
|
| 13 |
try:
|
| 14 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
| 15 |
if not spaces:
|
| 16 |
+
return [["No Spaces found", "", "", ""]]
|
| 17 |
|
| 18 |
results = []
|
| 19 |
|
|
|
|
| 23 |
status = getattr(info, "status", "unknown")
|
| 24 |
tags = getattr(info, "tags", [])
|
| 25 |
|
| 26 |
+
# Determine hardware type
|
| 27 |
runtime = getattr(info, "runtime", None)
|
| 28 |
if runtime:
|
| 29 |
requested_hw = getattr(runtime, "requested_hardware", None)
|
|
|
|
| 56 |
# Sort ZeroGPU first
|
| 57 |
results.sort(key=lambda x: 0 if x[2] == "ZeroGPU" else 1)
|
| 58 |
|
| 59 |
+
return results
|
|
|
|
|
|
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
+
return [[f"Error: {e}", "", "", ""]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# Gradio UI
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
+
gr.Markdown("## 🔍 Hugging Face Spaces ZeroGPU Scanner (Tabular View)")
|
| 68 |
|
| 69 |
with gr.Row():
|
| 70 |
username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
|
| 71 |
scan_button = gr.Button("Scan Spaces")
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
output_table = gr.Dataframe(
|
| 74 |
headers=["Space ID", "Status", "Hardware", "Tags"],
|
| 75 |
datatype=["str", "str", "str", "str"],
|
|
|
|
| 77 |
wrap=True
|
| 78 |
)
|
| 79 |
|
| 80 |
+
scan_button.click(scan_spaces_detailed, inputs=username_input, outputs=output_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
demo.launch()
|