rahul7star commited on
Commit
abebb3b
·
verified ·
1 Parent(s): 3dfd005

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -8,29 +8,28 @@ HF_TOKEN = os.getenv("HF_TOKEN")
8
  # Initialize HF API
9
  api = HfApi(token=HF_TOKEN)
10
 
11
- def check_zero_gpu(username: str):
12
  output = ""
13
  try:
14
- repos = api.list_models(author=username, token=HF_TOKEN)
15
- if not repos:
16
- return f"No repositories found for user '{username}'"
 
17
 
18
- for repo in repos:
19
  # Default: assume ZeroGPU
20
  zero_gpu = "Yes"
21
 
22
- # Check model card for hardware requirements
23
  try:
24
- card = api.model_info(repo_id=repo.modelId, token=HF_TOKEN)
25
- # If model has 'hardware' in card, and it mentions GPU, mark as No
26
- if hasattr(card, "hardware") and card.hardware:
27
- if any("gpu" in h.lower() for h in card.hardware):
28
  zero_gpu = "No"
29
  except Exception:
30
- # If info not available, keep as Yes
31
- pass
32
-
33
- output += f"{repo.modelId} | ZeroGPU: {zero_gpu}\n"
34
 
35
  except Exception as e:
36
  return f"Error: {e}"
@@ -39,11 +38,11 @@ def check_zero_gpu(username: str):
39
 
40
  # Gradio UI
41
  with gr.Blocks() as demo:
42
- gr.Markdown("## Hugging Face Repo ZeroGPU Checker")
43
  username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
44
- scan_button = gr.Button("Check Repositories")
45
  output_box = gr.Textbox(label="ZeroGPU Status", lines=25)
46
 
47
- scan_button.click(check_zero_gpu, inputs=username_input, outputs=output_box)
48
 
49
  demo.launch()
 
8
  # Initialize HF API
9
  api = HfApi(token=HF_TOKEN)
10
 
11
+ def check_spaces_zero_gpu(username: str):
12
  output = ""
13
  try:
14
+ # List all spaces for the user
15
+ spaces = api.list_spaces(author=username, token=HF_TOKEN)
16
+ if not spaces:
17
+ return f"No Spaces found for user '{username}'"
18
 
19
+ for space in spaces:
20
  # Default: assume ZeroGPU
21
  zero_gpu = "Yes"
22
 
23
+ # Check if space requires GPU
24
  try:
25
+ space_info = api.space_info(space_id=space.id, token=HF_TOKEN)
26
+ if getattr(space_info, "hardware", None):
27
+ if any("gpu" in h.lower() for h in space_info.hardware):
 
28
  zero_gpu = "No"
29
  except Exception:
30
+ pass # Keep as Yes if info unavailable
31
+
32
+ output += f"{space.id} | ZeroGPU: {zero_gpu}\n"
 
33
 
34
  except Exception as e:
35
  return f"Error: {e}"
 
38
 
39
  # Gradio UI
40
  with gr.Blocks() as demo:
41
+ gr.Markdown("## Hugging Face Spaces ZeroGPU Checker")
42
  username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
43
+ scan_button = gr.Button("Check Spaces")
44
  output_box = gr.Textbox(label="ZeroGPU Status", lines=25)
45
 
46
+ scan_button.click(check_spaces_zero_gpu, inputs=username_input, outputs=output_box)
47
 
48
  demo.launch()