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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -1,45 +1,49 @@
1
  import os
2
  import gradio as gr
3
- from huggingface_hub import HfApi, list_repo_files
4
 
5
- # Load HF token from environment variable
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
 
8
  # Initialize HF API
9
  api = HfApi(token=HF_TOKEN)
10
 
11
- def list_repos_files(username: str):
12
  output = ""
13
  try:
14
- # Get all models (repositories) for the user
15
  repos = api.list_models(author=username, token=HF_TOKEN)
16
  if not repos:
17
  return f"No repositories found for user '{username}'"
18
 
19
  for repo in repos:
20
- output += f"Repo: {repo.modelId}\n"
 
 
 
21
  try:
22
- files = list_repo_files(repo_id=repo.modelId, token=HF_TOKEN)
23
- if files:
24
- for f in files:
25
- output += f" - {f}\n"
26
- else:
27
- output += " (No files found)\n"
28
- except Exception as e:
29
- output += f" Failed to list files: {e}\n"
30
- output += "\n"
 
 
31
  except Exception as e:
32
  return f"Error: {e}"
33
-
34
  return output
35
 
36
  # Gradio UI
37
  with gr.Blocks() as demo:
38
- gr.Markdown("## Hugging Face User Repository Scanner (ZeroGPU)")
39
  username_input = gr.Textbox(label="Hugging Face Username", value="rahul7star")
40
- scan_button = gr.Button("Scan Repositories")
41
- output_box = gr.Textbox(label="Repository Files", lines=25)
42
 
43
- scan_button.click(list_repos_files, inputs=username_input, outputs=output_box)
44
 
45
  demo.launch()
 
1
  import os
2
  import gradio as gr
3
+ from huggingface_hub import HfApi
4
 
5
+ # Load HF token from environment variable if needed
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
 
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}"
37
+
38
  return output
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()