Spaces:
Runtime error
Runtime error
osanseviero
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,18 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
-
from huggingface_hub import list_models, list_datasets, list_spaces
|
4 |
|
5 |
# Helper function to get the total storage for models, datasets, or spaces
|
6 |
-
def get_total_storage(
|
7 |
if resource_type == "model":
|
8 |
-
resources = list_models(author=
|
9 |
url_base = "https://huggingface.co/api/models"
|
10 |
elif resource_type == "dataset":
|
11 |
-
resources = list_datasets(author=
|
12 |
url_base = "https://huggingface.co/api/datasets"
|
13 |
elif resource_type == "space":
|
14 |
-
resources = list_spaces(author=
|
15 |
url_base = "https://huggingface.co/api/spaces"
|
16 |
-
else:
|
17 |
-
raise ValueError("Invalid resource type. Choose 'model', 'dataset', or 'space'.")
|
18 |
|
19 |
total_storage = 0
|
20 |
for resource in resources:
|
@@ -27,17 +25,11 @@ def get_total_storage(author, resource_type, oauth_token: gr.OAuthToken | None):
|
|
27 |
|
28 |
return total_storage, len(resources)
|
29 |
|
30 |
-
def get_report(oauth_token: gr.OAuthToken
|
31 |
-
# Log in to Hugging Face using the provided API token
|
32 |
-
login(api_token)
|
33 |
-
|
34 |
-
# Replace with the actual author namespace
|
35 |
-
author = "your-namespace" # Example: 'osanseviero'
|
36 |
-
|
37 |
# Fetch storage and counts for models, datasets, and spaces
|
38 |
-
model_storage, n_models = get_total_storage(
|
39 |
-
dataset_storage, n_datasets = get_total_storage(
|
40 |
-
space_storage, n_spaces = get_total_storage(
|
41 |
|
42 |
# Total storage
|
43 |
total_storage = model_storage + dataset_storage + space_storage
|
@@ -49,8 +41,7 @@ def get_report(oauth_token: gr.OAuthToken | None):
|
|
49 |
|
50 |
# Generate a report
|
51 |
report = f"""
|
52 |
-
## Hugging Face Storage Report for {
|
53 |
-
|
54 |
- **Number of Models**: {n_models}
|
55 |
- **Number of Datasets**: {n_datasets}
|
56 |
- **Number of Spaces**: {n_spaces}
|
@@ -62,8 +53,8 @@ def get_report(oauth_token: gr.OAuthToken | None):
|
|
62 |
return report
|
63 |
|
64 |
# Gradio interface
|
65 |
-
def gradio_interface(
|
66 |
-
report = get_report(api_token)
|
67 |
return report
|
68 |
|
69 |
css = """
|
@@ -75,12 +66,12 @@ with gr.Blocks(css=css) as demo:
|
|
75 |
gr.Markdown("# Hugging Face Storage Report")
|
76 |
|
77 |
gr.LoginButton()
|
78 |
-
|
79 |
output = gr.Markdown()
|
80 |
|
81 |
# Button to trigger the report generation
|
82 |
report_button = gr.Button("Generate Report")
|
83 |
-
report_button.click(fn=gradio_interface, inputs=
|
84 |
|
85 |
# Launch the Gradio app
|
86 |
-
demo.launch()
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import list_models, list_datasets, list_spaces
|
4 |
|
5 |
# Helper function to get the total storage for models, datasets, or spaces
|
6 |
+
def get_total_storage(namespace, resource_type, oauth_token: gr.OAuthToken):
|
7 |
if resource_type == "model":
|
8 |
+
resources = list_models(author=namespace, token=oauth_token.token)
|
9 |
url_base = "https://huggingface.co/api/models"
|
10 |
elif resource_type == "dataset":
|
11 |
+
resources = list_datasets(author=namespace, token=oauth_token.token)
|
12 |
url_base = "https://huggingface.co/api/datasets"
|
13 |
elif resource_type == "space":
|
14 |
+
resources = list_spaces(author=namespace, token=oauth_token.token)
|
15 |
url_base = "https://huggingface.co/api/spaces"
|
|
|
|
|
16 |
|
17 |
total_storage = 0
|
18 |
for resource in resources:
|
|
|
25 |
|
26 |
return total_storage, len(resources)
|
27 |
|
28 |
+
def get_report(namespace, oauth_token: gr.OAuthToken):
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Fetch storage and counts for models, datasets, and spaces
|
30 |
+
model_storage, n_models = get_total_storage(namespace, "model", oauth_token)
|
31 |
+
dataset_storage, n_datasets = get_total_storage(namespace, "dataset", oauth_token)
|
32 |
+
space_storage, n_spaces = get_total_storage(namespace, "space", oauth_token)
|
33 |
|
34 |
# Total storage
|
35 |
total_storage = model_storage + dataset_storage + space_storage
|
|
|
41 |
|
42 |
# Generate a report
|
43 |
report = f"""
|
44 |
+
## Hugging Face Storage Report for {namespace}
|
|
|
45 |
- **Number of Models**: {n_models}
|
46 |
- **Number of Datasets**: {n_datasets}
|
47 |
- **Number of Spaces**: {n_spaces}
|
|
|
53 |
return report
|
54 |
|
55 |
# Gradio interface
|
56 |
+
def gradio_interface(namespace, oauth_token: gr.OAuthToken):
|
57 |
+
report = get_report(api_token, author)
|
58 |
return report
|
59 |
|
60 |
css = """
|
|
|
66 |
gr.Markdown("# Hugging Face Storage Report")
|
67 |
|
68 |
gr.LoginButton()
|
69 |
+
namespace = gr.Textbox(label="Enter Namespace (username or org)")
|
70 |
output = gr.Markdown()
|
71 |
|
72 |
# Button to trigger the report generation
|
73 |
report_button = gr.Button("Generate Report")
|
74 |
+
report_button.click(fn=gradio_interface, inputs=namespace, outputs=output)
|
75 |
|
76 |
# Launch the Gradio app
|
77 |
+
demo.launch()
|