Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,21 +6,24 @@ import pandas as pd
|
|
| 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
|
| 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.
|
| 24 |
task = model.pipeline_tag if hasattr(model, "pipeline_tag") else "N/A"
|
| 25 |
recent_models.append({
|
| 26 |
"Model ID": f'<a href="https://huggingface.co/{model.modelId}" target="_blank">{model.modelId}</a>',
|
|
@@ -41,10 +44,13 @@ def get_recent_models(min_likes, days_ago):
|
|
| 41 |
# Define the Gradio interface
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
gr.Markdown("# Model Drops Tracker ๐")
|
| 44 |
-
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.")
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Row():
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
btn = gr.Button("Run")
|
| 50 |
|
|
@@ -55,7 +61,7 @@ with gr.Blocks() as demo:
|
|
| 55 |
datatype=["html", "number", "str"],
|
| 56 |
)
|
| 57 |
|
| 58 |
-
btn.click(fn=get_recent_models, inputs=[likes_slider, days_slider], outputs=df)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
|
|
|
| 6 |
# Initialize the Hugging Face API
|
| 7 |
api = HfApi()
|
| 8 |
|
| 9 |
+
def get_recent_models(min_likes, days_ago, filter_substrings, search_substrings):
|
| 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 |
+
filter_substrings = [sub.strip().lower() for sub in filter_substrings.split(';')]
|
| 18 |
+
search_substrings = [term.strip().lower() for term in search_substrings.split(';')]
|
| 19 |
|
| 20 |
# Use a generator to fetch models in batches, sorted by likes in descending order
|
| 21 |
for model in api.list_models(sort="likes", direction=-1):
|
| 22 |
+
if model.likes >= min_likes:
|
| 23 |
if hasattr(model, "created_at") and model.created_at:
|
| 24 |
# Ensure created_at is offset-naive
|
| 25 |
created_at_date = model.created_at.replace(tzinfo=None)
|
| 26 |
+
if created_at_date >= start_date and not any(sub in model.modelId.lower() for sub in filter_substrings) and any(term in model.modelId.lower() for term in search_substrings):
|
| 27 |
task = model.pipeline_tag if hasattr(model, "pipeline_tag") else "N/A"
|
| 28 |
recent_models.append({
|
| 29 |
"Model ID": f'<a href="https://huggingface.co/{model.modelId}" target="_blank">{model.modelId}</a>',
|
|
|
|
| 44 |
# Define the Gradio interface
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
gr.Markdown("# Model Drops Tracker ๐")
|
| 47 |
+
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. Use `;` to split filter and search")
|
| 48 |
+
with gr.Row():
|
| 49 |
+
likes_slider = gr.Slider(minimum=1, maximum=100, step=1, value=5, label="Minimum Likes")
|
| 50 |
+
days_slider = gr.Slider(minimum=1, maximum=30, step=1, value=3, label="Days Ago")
|
| 51 |
with gr.Row():
|
| 52 |
+
filter_text = gr.Text(label="Filter", max_lines=1)
|
| 53 |
+
search_text = gr.Text(label="Search", max_lines=1)
|
| 54 |
|
| 55 |
btn = gr.Button("Run")
|
| 56 |
|
|
|
|
| 61 |
datatype=["html", "number", "str"],
|
| 62 |
)
|
| 63 |
|
| 64 |
+
btn.click(fn=get_recent_models, inputs=[likes_slider, days_slider, filter_text, search_text], outputs=df)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
demo.launch()
|