Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,26 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from huggingface_hub import HfApi, list_repo_files
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Initialize HF API
|
| 5 |
-
api = HfApi()
|
| 6 |
|
| 7 |
def list_repos_files(username: str):
|
| 8 |
"""List all repos and files for a given Hugging Face username"""
|
| 9 |
output = ""
|
| 10 |
try:
|
| 11 |
-
|
|
|
|
| 12 |
if not repos:
|
| 13 |
return f"No repositories found for user '{username}'"
|
| 14 |
|
| 15 |
for repo in repos:
|
| 16 |
-
output += f"Repo: {repo.
|
| 17 |
try:
|
| 18 |
-
files = list_repo_files(repo_id=repo.
|
| 19 |
if files:
|
| 20 |
for f in files:
|
| 21 |
output += f" - {f}\n"
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
from huggingface_hub import HfApi, list_repo_files
|
| 4 |
|
| 5 |
+
# If you have a token for private repos, put it here; else None
|
| 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 |
"""List all repos and files for a given Hugging Face username"""
|
| 13 |
output = ""
|
| 14 |
try:
|
| 15 |
+
# Use new method
|
| 16 |
+
repos = api.list_repositories(repo_type="model", author=username)
|
| 17 |
if not repos:
|
| 18 |
return f"No repositories found for user '{username}'"
|
| 19 |
|
| 20 |
for repo in repos:
|
| 21 |
+
output += f"Repo: {repo.modelId}\n"
|
| 22 |
try:
|
| 23 |
+
files = list_repo_files(repo_id=repo.modelId, token=HF_TOKEN)
|
| 24 |
if files:
|
| 25 |
for f in files:
|
| 26 |
output += f" - {f}\n"
|