first push
Browse files- README.md +55 -0
- hf-modelf-family-stats-gradio.py +90 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -10,3 +10,58 @@ pinned: false
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
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 |
+
|
20 |
+
- Search for models by name or keyword
|
21 |
+
- View detailed statistics including:
|
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 |
+
|
29 |
+
## Installation
|
30 |
+
|
31 |
+
1. Clone this repository:
|
32 |
+
```bash
|
33 |
+
git clone https://github.com/yourusername/model-stats-search-keywords.git
|
34 |
+
cd model-stats-search-keywords
|
35 |
+
```
|
36 |
+
|
37 |
+
2. Install the required dependencies:
|
38 |
+
```bash
|
39 |
+
pip install -r requirements.txt
|
40 |
+
```
|
41 |
+
|
42 |
+
## Usage
|
43 |
+
|
44 |
+
1. Run the application:
|
45 |
+
```bash
|
46 |
+
python hf-modelf-family-stats-gradio.py
|
47 |
+
```
|
48 |
+
|
49 |
+
2. Open your web browser and navigate to the URL shown in the terminal (typically http://127.0.0.1:7860)
|
50 |
+
|
51 |
+
3. Enter a search term in the text box (e.g., "gemma", "llama") and click "Search"
|
52 |
+
|
53 |
+
4. View the results in the table and download the data as CSV if needed
|
54 |
+
|
55 |
+
## Dependencies
|
56 |
+
|
57 |
+
- gradio
|
58 |
+
- huggingface-hub
|
59 |
+
- pandas
|
60 |
+
|
61 |
+
## License
|
62 |
+
|
63 |
+
[Add your license information here]
|
64 |
+
|
65 |
+
## Contributing
|
66 |
+
|
67 |
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
hf-modelf-family-stats-gradio.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
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
|
11 |
+
api = HfApi()
|
12 |
+
|
13 |
+
# Create a temporary file for the CSV
|
14 |
+
temp_dir = tempfile.mkdtemp()
|
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 all-time download statistics...")
|
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 |
+
|
25 |
+
# Create and write to CSV
|
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)", "Trending Score"])
|
30 |
+
|
31 |
+
# Process models
|
32 |
+
model_count = 0
|
33 |
+
for model in models_generator:
|
34 |
+
# Write to CSV
|
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 |
+
|
43 |
+
# Read the CSV file into a pandas DataFrame
|
44 |
+
df = pd.read_csv(output_file)
|
45 |
+
|
46 |
+
# Return both the DataFrame, status message, and the CSV file path
|
47 |
+
return df, f"Found {model_count} models for search term '{search_term}'", str(output_file)
|
48 |
+
|
49 |
+
# Create the Gradio interface
|
50 |
+
with gr.Blocks(title="Hugging Face Model Statistics") as demo:
|
51 |
+
gr.Markdown("# Hugging Face Model Statistics")
|
52 |
+
gr.Markdown("Enter a search term to find model statistics from Hugging Face Hub")
|
53 |
+
|
54 |
+
with gr.Row():
|
55 |
+
search_input = gr.Textbox(
|
56 |
+
label="Search Term",
|
57 |
+
placeholder="Enter a model name or keyword (e.g., 'gemma', 'llama')",
|
58 |
+
value="gemma"
|
59 |
+
)
|
60 |
+
search_button = gr.Button("Search")
|
61 |
+
|
62 |
+
with gr.Row():
|
63 |
+
output_table = gr.Dataframe(
|
64 |
+
headers=["Model ID", "Downloads (30 days)", "Downloads (All Time)", "Trending Score"],
|
65 |
+
datatype=["str", "number", "number", "number"],
|
66 |
+
label="Model Statistics"
|
67 |
+
)
|
68 |
+
status_message = gr.Textbox(label="Status")
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
download_button = gr.Button("Download CSV")
|
72 |
+
csv_file = gr.File(label="CSV File", visible=False)
|
73 |
+
|
74 |
+
# Store the CSV file path in a state
|
75 |
+
csv_path = gr.State()
|
76 |
+
|
77 |
+
search_button.click(
|
78 |
+
fn=get_model_stats,
|
79 |
+
inputs=search_input,
|
80 |
+
outputs=[output_table, status_message, csv_path]
|
81 |
+
)
|
82 |
+
|
83 |
+
download_button.click(
|
84 |
+
fn=lambda x: x,
|
85 |
+
inputs=csv_path,
|
86 |
+
outputs=csv_file
|
87 |
+
)
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
huggingface-hub
|
3 |
+
pandas
|