Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,11 @@ from huggingface_hub import HfApi
|
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
api = HfApi(token=HF_TOKEN)
|
| 7 |
|
| 8 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
output = ""
|
| 10 |
try:
|
| 11 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
|
@@ -17,24 +21,39 @@ def scan_spaces(username: str):
|
|
| 17 |
info = api.space_info(space.id, token=HF_TOKEN)
|
| 18 |
status = getattr(info, "status", "unknown")
|
| 19 |
tags = getattr(info, "tags", [])
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
output += f"{space.id} | Error retrieving info: {e}\n"
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return f"Error: {e}"
|
|
|
|
| 29 |
return output
|
| 30 |
|
| 31 |
# Gradio UI
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
-
gr.Markdown("## Hugging Face Spaces
|
| 34 |
username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
|
| 35 |
scan_button = gr.Button("Scan Spaces")
|
| 36 |
-
output_box = gr.Textbox(label="
|
| 37 |
|
| 38 |
-
scan_button.click(
|
| 39 |
|
| 40 |
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 log all metadata.
|
| 11 |
+
Mark Hardware: ZeroGPU if CPU only.
|
| 12 |
+
"""
|
| 13 |
output = ""
|
| 14 |
try:
|
| 15 |
spaces = api.list_spaces(author=username, token=HF_TOKEN)
|
|
|
|
| 21 |
info = api.space_info(space.id, token=HF_TOKEN)
|
| 22 |
status = getattr(info, "status", "unknown")
|
| 23 |
tags = getattr(info, "tags", [])
|
| 24 |
+
hardware_field = getattr(info, "hardware", None)
|
| 25 |
+
|
| 26 |
+
# Determine ZeroGPU
|
| 27 |
+
if hardware_field:
|
| 28 |
+
hardware = "ZeroGPU" if all("cpu" in h.lower() for h in hardware_field) else "GPU"
|
| 29 |
+
else:
|
| 30 |
+
# fallback to tags
|
| 31 |
+
hardware = "ZeroGPU" if "cpu" in tags else "GPU"
|
| 32 |
+
|
| 33 |
+
# Log all metadata
|
| 34 |
+
output += f"Space: {space.id}\n"
|
| 35 |
+
output += f" Status: {status}\n"
|
| 36 |
+
output += f" Hardware: {hardware}\n"
|
| 37 |
+
output += f" Tags: {tags}\n"
|
| 38 |
+
output += f" Raw metadata: {info}\n"
|
| 39 |
+
output += "-"*50 + "\n"
|
| 40 |
+
|
| 41 |
except Exception as e:
|
| 42 |
output += f"{space.id} | Error retrieving info: {e}\n"
|
| 43 |
+
output += "-"*50 + "\n"
|
| 44 |
+
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error: {e}"
|
| 47 |
+
|
| 48 |
return output
|
| 49 |
|
| 50 |
# Gradio UI
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
+
gr.Markdown("## Hugging Face Spaces Detailed ZeroGPU Scanner")
|
| 53 |
username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
|
| 54 |
scan_button = gr.Button("Scan Spaces")
|
| 55 |
+
output_box = gr.Textbox(label="Detailed Space Metadata", lines=30)
|
| 56 |
|
| 57 |
+
scan_button.click(scan_spaces_detailed, inputs=username_input, outputs=output_box)
|
| 58 |
|
| 59 |
demo.launch()
|