add total
Browse files
app.py
CHANGED
@@ -21,6 +21,10 @@ def get_model_stats(search_term):
|
|
21 |
sort="_id" # Sort by ID to avoid timeout issues
|
22 |
)
|
23 |
|
|
|
|
|
|
|
|
|
24 |
# Create and write to CSV
|
25 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
26 |
csv_writer = csv.writer(csvfile)
|
@@ -30,24 +34,39 @@ def get_model_stats(search_term):
|
|
30 |
# Process models
|
31 |
model_count = 0
|
32 |
for model in models_generator:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Write to CSV
|
34 |
csv_writer.writerow([
|
35 |
getattr(model, 'id', "Unknown"),
|
36 |
-
|
37 |
-
|
38 |
])
|
39 |
model_count += 1
|
40 |
|
41 |
# Read the CSV file into a pandas DataFrame
|
42 |
df = pd.read_csv(output_file)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Return both the DataFrame, status message, and the CSV file path
|
45 |
-
return df,
|
46 |
|
47 |
# Create the Gradio interface
|
48 |
with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
49 |
gr.Markdown("# Hugging Face Model Statistics")
|
50 |
-
gr.Markdown("Enter a search term to find model statistics from
|
51 |
|
52 |
with gr.Row():
|
53 |
search_input = gr.Textbox(
|
@@ -63,7 +82,7 @@ with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
|
63 |
datatype=["str", "number", "number"],
|
64 |
label="Model Statistics"
|
65 |
)
|
66 |
-
status_message = gr.Textbox(label="Status")
|
67 |
|
68 |
with gr.Row():
|
69 |
download_button = gr.Button("Download CSV")
|
|
|
21 |
sort="_id" # Sort by ID to avoid timeout issues
|
22 |
)
|
23 |
|
24 |
+
# Initialize counters for total downloads
|
25 |
+
total_30day_downloads = 0
|
26 |
+
total_alltime_downloads = 0
|
27 |
+
|
28 |
# Create and write to CSV
|
29 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
30 |
csv_writer = csv.writer(csvfile)
|
|
|
34 |
# Process models
|
35 |
model_count = 0
|
36 |
for model in models_generator:
|
37 |
+
# Get download counts
|
38 |
+
downloads_30day = getattr(model, 'downloads', 0)
|
39 |
+
downloads_alltime = getattr(model, 'downloads_all_time', 0)
|
40 |
+
|
41 |
+
# Add to totals
|
42 |
+
total_30day_downloads += downloads_30day
|
43 |
+
total_alltime_downloads += downloads_alltime
|
44 |
+
|
45 |
# Write to CSV
|
46 |
csv_writer.writerow([
|
47 |
getattr(model, 'id', "Unknown"),
|
48 |
+
downloads_30day,
|
49 |
+
downloads_alltime
|
50 |
])
|
51 |
model_count += 1
|
52 |
|
53 |
# Read the CSV file into a pandas DataFrame
|
54 |
df = pd.read_csv(output_file)
|
55 |
|
56 |
+
# Create status message with total downloads
|
57 |
+
status_message = (
|
58 |
+
f"Found {model_count} models for search term '{search_term}'\n"
|
59 |
+
f"Total 30-day downloads: {total_30day_downloads:,}\n"
|
60 |
+
f"Total all-time downloads: {total_alltime_downloads:,}"
|
61 |
+
)
|
62 |
+
|
63 |
# Return both the DataFrame, status message, and the CSV file path
|
64 |
+
return df, status_message, str(output_file)
|
65 |
|
66 |
# Create the Gradio interface
|
67 |
with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
68 |
gr.Markdown("# Hugging Face Model Statistics")
|
69 |
+
gr.Markdown("Enter a search term to find model statistics from Hugging Face Hub")
|
70 |
|
71 |
with gr.Row():
|
72 |
search_input = gr.Textbox(
|
|
|
82 |
datatype=["str", "number", "number"],
|
83 |
label="Model Statistics"
|
84 |
)
|
85 |
+
status_message = gr.Textbox(label="Status", lines=3) # Increased lines to show all stats
|
86 |
|
87 |
with gr.Row():
|
88 |
download_button = gr.Button("Download CSV")
|