fdaudens HF staff commited on
Commit
2823b9e
β€’
1 Parent(s): 20dde2a
Files changed (2) hide show
  1. app.py +59 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import HfApi
3
+ from datetime import datetime, timedelta
4
+ import pandas as pd
5
+
6
+ # Initialize the Hugging Face API
7
+ api = HfApi()
8
+
9
+ def get_recent_models(min_likes, days_ago):
10
+ # Get the current date and date from `days_ago` days ago
11
+ today = datetime.utcnow().replace(tzinfo=None)
12
+ start_date = (today - timedelta(days=days_ago)).replace(tzinfo=None)
13
+
14
+ # Initialize an empty list to store the filtered models
15
+ recent_models = []
16
+
17
+ # Use a generator to fetch models in batches, sorted by likes in descending order
18
+ for model in api.list_models(sort="likes", direction=-1):
19
+ if model.likes > 10:
20
+ if hasattr(model, "created_at") and model.created_at:
21
+ # Ensure created_at is offset-naive
22
+ created_at_date = model.created_at.replace(tzinfo=None)
23
+ if created_at_date >= start_date and model.likes >= min_likes:
24
+ recent_models.append({
25
+ "Model ID": f'<a href="https://huggingface.co/{model.modelId}" target="_blank">{model.modelId}</a>',
26
+ "Likes": model.likes,
27
+ "Creation Date": model.created_at.strftime("%Y-%m-%d %H:%M")
28
+ })
29
+ else:
30
+ # Since the models are sorted by likes in descending order,
31
+ # we can stop once we hit a model with 10 or fewer likes
32
+ break
33
+
34
+ # Convert the list of dictionaries to a pandas DataFrame
35
+ df = pd.DataFrame(recent_models)
36
+
37
+ return df
38
+
39
+ # Define the Gradio interface
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("# Model Drops Tracker πŸš€")
42
+ gr.Markdown("Overwhelmed by the rapid pace of model releases? πŸ˜… You're not alone! That's exactly why I built this tool. Easily filter recent models from the Hub by setting a minimum number of likes and the number of days since their release. Click on a model to see its card.")
43
+ with gr.Row():
44
+ likes_slider = gr.Slider(minimum=0, maximum=100, step=10, value=10, label="Minimum Likes")
45
+ days_slider = gr.Slider(minimum=1, maximum=7, step=1, value=1, label="Days Ago")
46
+
47
+ btn = gr.Button("Run")
48
+
49
+ with gr.Column():
50
+ df = gr.DataFrame(
51
+ headers=["Model ID", "Likes", "Creation Date"],
52
+ wrap=True,
53
+ datatype=["html", "number", "str"],
54
+ )
55
+
56
+ btn.click(fn=get_recent_models, inputs=[likes_slider, days_slider], outputs=df)
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ huggingface_hub
3
+ pytz
4
+ pandas