rahul7star commited on
Commit
aee5791
·
verified ·
1 Parent(s): ff307af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -5,9 +5,10 @@ from huggingface_hub import HfApi
5
  HF_TOKEN = os.getenv("HF_TOKEN")
6
  api = HfApi(token=HF_TOKEN)
7
 
8
- def scan_spaces_zero_a10g(username: str):
9
  """
10
- Scan all Spaces for a user and suggest ZeroGPU if SpaceRuntime.hardware == 'zero-a10g'
 
11
  """
12
  output = ""
13
  try:
@@ -19,18 +20,27 @@ def scan_spaces_zero_a10g(username: str):
19
  try:
20
  info = api.space_info(space.id, token=HF_TOKEN)
21
  status = getattr(info, "status", "unknown")
 
 
22
 
23
- # Check if SpaceRuntime object exists and has hardware attribute
24
- space_runtime = getattr(info, "SpaceRuntime", None)
25
- if space_runtime and getattr(space_runtime, "hardware", "").lower() == "zero-a10g":
26
- hardware = "ZeroGPU"
27
  else:
28
- hardware = "None"
 
29
 
30
- output += f"{space.id} | Status: {status} | Hardware: {hardware}\n"
 
 
 
 
 
 
31
 
32
  except Exception as e:
33
  output += f"{space.id} | Error retrieving info: {e}\n"
 
34
 
35
  except Exception as e:
36
  return f"Error: {e}"
@@ -39,11 +49,11 @@ def scan_spaces_zero_a10g(username: str):
39
 
40
  # Gradio UI
41
  with gr.Blocks() as demo:
42
- gr.Markdown("## Hugging Face Spaces Zero-A10G (ZeroGPU) Scanner")
43
  username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
44
  scan_button = gr.Button("Scan Spaces")
45
- output_box = gr.Textbox(label="ZeroGPU Status", lines=25)
46
 
47
- scan_button.click(scan_spaces_zero_a10g, inputs=username_input, outputs=output_box)
48
 
49
  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:
 
20
  try:
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}"
 
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()