30 days
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
|
2 |
import csv
|
3 |
-
import os
|
4 |
-
import gradio as gr
|
5 |
import pandas as pd
|
|
|
|
|
6 |
from pathlib import Path
|
7 |
-
import tempfile
|
8 |
|
9 |
def get_model_stats(search_term):
|
10 |
# Initialize the API
|
@@ -15,10 +14,10 @@ def get_model_stats(search_term):
|
|
15 |
output_file = Path(temp_dir) / f"{search_term}_models_alltime.csv"
|
16 |
|
17 |
# Get the generator of models with the working sort parameter
|
18 |
-
print(f"Fetching {search_term} models with
|
19 |
models_generator = api.list_models(
|
20 |
search=search_term,
|
21 |
-
expand=["downloadsAllTime"],
|
22 |
sort="_id" # Sort by ID to avoid timeout issues
|
23 |
)
|
24 |
|
@@ -26,7 +25,7 @@ def get_model_stats(search_term):
|
|
26 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
27 |
csv_writer = csv.writer(csvfile)
|
28 |
# Write header
|
29 |
-
csv_writer.writerow(["Model ID", "Downloads (30 days)", "Downloads (All Time)"
|
30 |
|
31 |
# Process models
|
32 |
model_count = 0
|
@@ -35,8 +34,7 @@ def get_model_stats(search_term):
|
|
35 |
csv_writer.writerow([
|
36 |
getattr(model, 'id', "Unknown"),
|
37 |
getattr(model, 'downloads', 0), # Last 30 days downloads
|
38 |
-
getattr(model, 'downloads_all_time', 0)
|
39 |
-
getattr(model, 'trending_score', 0)
|
40 |
])
|
41 |
model_count += 1
|
42 |
|
@@ -61,8 +59,8 @@ with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
|
61 |
|
62 |
with gr.Row():
|
63 |
output_table = gr.Dataframe(
|
64 |
-
headers=["Model ID", "Downloads (30 days)", "Downloads (All Time)"
|
65 |
-
datatype=["str", "number", "number"
|
66 |
label="Model Statistics"
|
67 |
)
|
68 |
status_message = gr.Textbox(label="Status")
|
@@ -87,4 +85,4 @@ with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
|
87 |
)
|
88 |
|
89 |
if __name__ == "__main__":
|
90 |
-
demo.launch()
|
|
|
1 |
+
import tempfile
|
2 |
import csv
|
|
|
|
|
3 |
import pandas as pd
|
4 |
+
import gradio as gr
|
5 |
+
from huggingface_hub import HfApi
|
6 |
from pathlib import Path
|
|
|
7 |
|
8 |
def get_model_stats(search_term):
|
9 |
# Initialize the API
|
|
|
14 |
output_file = Path(temp_dir) / f"{search_term}_models_alltime.csv"
|
15 |
|
16 |
# Get the generator of models with the working sort parameter
|
17 |
+
print(f"Fetching {search_term} models with download statistics...")
|
18 |
models_generator = api.list_models(
|
19 |
search=search_term,
|
20 |
+
expand=["downloads", "downloadsAllTime"], # Get both 30-day and all-time downloads
|
21 |
sort="_id" # Sort by ID to avoid timeout issues
|
22 |
)
|
23 |
|
|
|
25 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
26 |
csv_writer = csv.writer(csvfile)
|
27 |
# Write header
|
28 |
+
csv_writer.writerow(["Model ID", "Downloads (30 days)", "Downloads (All Time)"])
|
29 |
|
30 |
# Process models
|
31 |
model_count = 0
|
|
|
34 |
csv_writer.writerow([
|
35 |
getattr(model, 'id', "Unknown"),
|
36 |
getattr(model, 'downloads', 0), # Last 30 days downloads
|
37 |
+
getattr(model, 'downloads_all_time', 0)
|
|
|
38 |
])
|
39 |
model_count += 1
|
40 |
|
|
|
59 |
|
60 |
with gr.Row():
|
61 |
output_table = gr.Dataframe(
|
62 |
+
headers=["Model ID", "Downloads (30 days)", "Downloads (All Time)"],
|
63 |
+
datatype=["str", "number", "number"],
|
64 |
label="Model Statistics"
|
65 |
)
|
66 |
status_message = gr.Textbox(label="Status")
|
|
|
85 |
)
|
86 |
|
87 |
if __name__ == "__main__":
|
88 |
+
demo.launch()
|