rahul7star commited on
Commit
fba00bc
·
verified ·
1 Parent(s): b53506b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
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 sort ZeroGPU spaces first.
11
  """
12
  try:
13
  spaces = api.list_spaces(author=username, token=HF_TOKEN)
14
  if not spaces:
15
- return f"No Spaces found for user '{username}'"
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
- "id": space.id,
42
- "status": status,
43
- "hardware": hardware,
44
- "tags": tags
45
  })
46
 
47
  except Exception as e:
48
  results.append({
49
- "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
- # Format output for Gradio (hide raw metadata)
59
- output = ""
60
- for r in results:
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 output
69
 
70
  except Exception as e:
71
- return f"Error: {e}"
72
 
73
  # Gradio UI
74
  with gr.Blocks() as demo:
75
- gr.Markdown("## Hugging Face Spaces ZeroGPU Scanner (Sorted)")
76
- username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
 
 
 
 
77
  scan_button = gr.Button("Scan Spaces")
78
- output_box = gr.Textbox(label="Spaces Summary", lines=30)
79
 
80
- scan_button.click(scan_spaces_detailed, inputs=username_input, outputs=output_box)
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()