fdaudens HF Staff commited on
Commit
1d6be2f
·
1 Parent(s): c1e46c1

test 30 days

Browse files
Files changed (2) hide show
  1. README.md +1 -2
  2. hf-modelf-family-stats-gradio.py +88 -0
README.md CHANGED
@@ -13,7 +13,7 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
13
 
14
  # Hugging Face Model Statistics Search
15
 
16
- A web application built with Gradio that allows users to search and analyze model statistics from the Hugging Face Hub. The application provides detailed information about model downloads, trending scores, and allows exporting the data to CSV format.
17
 
18
  ## Features
19
 
@@ -22,7 +22,6 @@ A web application built with Gradio that allows users to search and analyze mode
22
  - Model ID
23
  - Downloads (30 days)
24
  - Downloads (All Time)
25
- - Trending Score
26
  - Export results to CSV
27
  - User-friendly web interface
28
 
 
13
 
14
  # Hugging Face Model Statistics Search
15
 
16
+ A web application built with Gradio that allows users to search and analyze model statistics from the Hugging Face Hub. The application provides detailed information about model downloads and allows exporting the data to CSV format.
17
 
18
  ## Features
19
 
 
22
  - Model ID
23
  - Downloads (30 days)
24
  - Downloads (All Time)
 
25
  - Export results to CSV
26
  - User-friendly web interface
27
 
hf-modelf-family-stats-gradio.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
10
+ api = HfApi()
11
+
12
+ # Create a temporary file for the CSV
13
+ temp_dir = tempfile.mkdtemp()
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
+
24
+ # Create and write to CSV
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
32
+ for model in models_generator:
33
+ # Write to CSV
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
+
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, f"Found {model_count} models for search term '{search_term}'", str(output_file)
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 Hugging Face Hub")
51
+
52
+ with gr.Row():
53
+ search_input = gr.Textbox(
54
+ label="Search Term",
55
+ placeholder="Enter a model name or keyword (e.g., 'gemma', 'llama')",
56
+ value="gemma"
57
+ )
58
+ search_button = gr.Button("Search")
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")
67
+
68
+ with gr.Row():
69
+ download_button = gr.Button("Download CSV")
70
+ csv_file = gr.File(label="CSV File", visible=False)
71
+
72
+ # Store the CSV file path in a state
73
+ csv_path = gr.State()
74
+
75
+ search_button.click(
76
+ fn=get_model_stats,
77
+ inputs=search_input,
78
+ outputs=[output_table, status_message, csv_path]
79
+ )
80
+
81
+ download_button.click(
82
+ fn=lambda x: x,
83
+ inputs=csv_path,
84
+ outputs=csv_file
85
+ )
86
+
87
+ if __name__ == "__main__":
88
+ demo.launch()