Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,14 @@ from huggingface_hub import HfApi
|
|
| 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, mark ZeroGPU, and
|
| 11 |
"""
|
| 12 |
try:
|
| 13 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
| 14 |
if not spaces:
|
| 15 |
-
return
|
| 16 |
|
| 17 |
results = []
|
| 18 |
|
|
@@ -38,45 +38,43 @@ def scan_spaces_detailed(username: str):
|
|
| 38 |
hardware = "ZeroGPU" if "cpu" in tags else "GPU"
|
| 39 |
|
| 40 |
results.append({
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
})
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
results.append({
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
})
|
| 54 |
|
| 55 |
# Sort ZeroGPU spaces first
|
| 56 |
-
results.sort(key=lambda x: 0 if x["
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
line = f"Space: {r['id']}\n"
|
| 62 |
-
line += f" Status: {r['status']}\n"
|
| 63 |
-
line += f" Hardware: {r['hardware']}\n"
|
| 64 |
-
line += f" Tags: {r['tags']}\n"
|
| 65 |
-
line += "-"*50 + "\n"
|
| 66 |
-
output += line
|
| 67 |
|
| 68 |
-
return
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
-
return
|
| 72 |
|
| 73 |
# Gradio UI
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
-
gr.Markdown("## Hugging Face Spaces
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
scan_button = gr.Button("Scan Spaces")
|
| 78 |
-
|
| 79 |
|
| 80 |
-
scan_button.click(scan_spaces_detailed, inputs=username_input, outputs=
|
| 81 |
|
| 82 |
demo.launch()
|
|
|
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
api = HfApi(token=HF_TOKEN)
|
| 7 |
|
| 8 |
+
def scan_spaces_detailed(username: str, filter_hw: str):
|
| 9 |
"""
|
| 10 |
+
Scan all Spaces for a user, mark ZeroGPU, and filter by hardware.
|
| 11 |
"""
|
| 12 |
try:
|
| 13 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
| 14 |
if not spaces:
|
| 15 |
+
return []
|
| 16 |
|
| 17 |
results = []
|
| 18 |
|
|
|
|
| 38 |
hardware = "ZeroGPU" if "cpu" in tags else "GPU"
|
| 39 |
|
| 40 |
results.append({
|
| 41 |
+
"Space ID": space.id,
|
| 42 |
+
"Status": status,
|
| 43 |
+
"Hardware": hardware,
|
| 44 |
+
"Tags": ", ".join(tags)
|
| 45 |
})
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
results.append({
|
| 49 |
+
"Space ID": space.id,
|
| 50 |
+
"Status": f"Error retrieving info: {e}",
|
| 51 |
+
"Hardware": "Unknown",
|
| 52 |
+
"Tags": ""
|
| 53 |
})
|
| 54 |
|
| 55 |
# Sort ZeroGPU spaces first
|
| 56 |
+
results.sort(key=lambda x: 0 if x["Hardware"] == "ZeroGPU" else 1)
|
| 57 |
|
| 58 |
+
# Apply hardware filter
|
| 59 |
+
if filter_hw != "All":
|
| 60 |
+
results = [r for r in results if r["Hardware"] == filter_hw]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
return results
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
+
return [{"Space ID": "Error", "Status": str(e), "Hardware": "", "Tags": ""}]
|
| 66 |
|
| 67 |
# Gradio UI
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("## Hugging Face Spaces Scanner with Hardware Filter")
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
|
| 73 |
+
filter_hw = gr.Dropdown(choices=["All", "ZeroGPU", "GPU"], value="All", label="Filter by Hardware")
|
| 74 |
+
|
| 75 |
scan_button = gr.Button("Scan Spaces")
|
| 76 |
+
output_table = gr.Dataframe(headers=["Space ID", "Status", "Hardware", "Tags"], datatype=["str","str","str","str"], interactive=False)
|
| 77 |
|
| 78 |
+
scan_button.click(scan_spaces_detailed, inputs=[username_input, filter_hw], outputs=output_table)
|
| 79 |
|
| 80 |
demo.launch()
|