|
import gradio as gr |
|
import requests |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
import seaborn as sns |
|
from datetime import datetime, timedelta |
|
import plotly.graph_objects as go |
|
import numpy as np |
|
import json |
|
|
|
|
|
target_spaces = { |
|
"ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama", |
|
"ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D", |
|
"fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX", |
|
"fantos/flx8lora": "https://huggingface.co/spaces/fantos/flx8lora", |
|
"ginigen/Canvas": "https://huggingface.co/spaces/ginigen/Canvas", |
|
"fantaxy/erotica": "https://huggingface.co/spaces/fantaxy/erotica", |
|
"ginipick/time-machine": "https://huggingface.co/spaces/ginipick/time-machine", |
|
"aiqcamp/FLUX-VisionReply": "https://huggingface.co/spaces/aiqcamp/FLUX-VisionReply", |
|
"openfree/Tetris-Game": "https://huggingface.co/spaces/openfree/Tetris-Game", |
|
"openfree/everychat": "https://huggingface.co/spaces/openfree/everychat", |
|
"VIDraft/mouse1": "https://huggingface.co/spaces/VIDraft/mouse1", |
|
"kolaslab/alpha-go": "https://huggingface.co/spaces/kolaslab/alpha-go", |
|
"ginipick/text3d": "https://huggingface.co/spaces/ginipick/text3d", |
|
"openfree/trending-board": "https://huggingface.co/spaces/openfree/trending-board", |
|
"cutechicken/tankwar": "https://huggingface.co/spaces/cutechicken/tankwar", |
|
"openfree/game-jewel": "https://huggingface.co/spaces/openfree/game-jewel", |
|
"VIDraft/mouse-chat": "https://huggingface.co/spaces/VIDraft/mouse-chat", |
|
"ginipick/AccDiffusion": "https://huggingface.co/spaces/ginipick/AccDiffusion", |
|
"aiqtech/Particle-Accelerator-Simulation": "https://huggingface.co/spaces/aiqtech/Particle-Accelerator-Simulation", |
|
"openfree/GiniGEN": "https://huggingface.co/spaces/openfree/GiniGEN", |
|
"kolaslab/3DAudio-Spectrum-Analyzer": "https://huggingface.co/spaces/kolaslab/3DAudio-Spectrum-Analyzer", |
|
"openfree/trending-news-24": "https://huggingface.co/spaces/openfree/trending-news-24", |
|
"ginipick/Realtime-FLUX": "https://huggingface.co/spaces/ginipick/Realtime-FLUX", |
|
"VIDraft/prime-number": "https://huggingface.co/spaces/VIDraft/prime-number", |
|
"kolaslab/zombie-game": "https://huggingface.co/spaces/kolaslab/zombie-game", |
|
"fantos/miro-game": "https://huggingface.co/spaces/fantos/miro-game", |
|
"kolaslab/shooting": "https://huggingface.co/spaces/kolaslab/shooting", |
|
"VIDraft/Mouse-Hackathon": "https://huggingface.co/spaces/VIDraft/Mouse-Hackathon", |
|
"upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard", |
|
"LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo", |
|
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena" |
|
} |
|
|
|
def get_trending_spaces(date): |
|
url = f"https://huggingface.co/api/spaces/trending?date={date}&limit=300" |
|
response = requests.get(url) |
|
if response.status_code == 200: |
|
return response.json() |
|
return None |
|
|
|
def get_space_rank(spaces, space_id): |
|
for idx, space in enumerate(spaces, 1): |
|
if space.get('id', '') == space_id: |
|
return idx |
|
return None |
|
|
|
def fetch_and_analyze_data(): |
|
start_date = datetime(2023, 12, 1) |
|
end_date = datetime(2023, 12, 31) |
|
dates = [(start_date + timedelta(days=x)).strftime('%Y-%m-%d') |
|
for x in range((end_date - start_date).days + 1)] |
|
|
|
trending_data = {} |
|
target_space_ranks = {space: [] for space in target_spaces.keys()} |
|
|
|
for date in dates: |
|
spaces = get_trending_spaces(date) |
|
if spaces: |
|
trending_data[date] = spaces |
|
for space_id in target_spaces.keys(): |
|
rank = get_space_rank(spaces, space_id) |
|
target_space_ranks[space_id].append(rank) |
|
|
|
return trending_data, target_space_ranks, dates |
|
|
|
def create_trend_plot(trending_data, target_space_ranks, dates): |
|
fig = go.Figure() |
|
|
|
for space_id, ranks in target_space_ranks.items(): |
|
fig.add_trace(go.Scatter( |
|
x=dates, |
|
y=ranks, |
|
name=space_id, |
|
mode='lines+markers' |
|
)) |
|
|
|
fig.update_layout( |
|
title='Trending Ranks Over Time', |
|
xaxis_title='Date', |
|
yaxis_title='Rank', |
|
yaxis_autorange='reversed', |
|
height=800 |
|
) |
|
|
|
return fig |
|
|
|
def create_space_info_html(trending_data): |
|
latest_date = max(trending_data.keys()) |
|
latest_spaces = trending_data[latest_date] |
|
|
|
html_content = "<div style='padding: 20px;'>" |
|
html_content += f"<h2>Latest Rankings ({latest_date})</h2>" |
|
|
|
for space_id, url in target_spaces.items(): |
|
rank = get_space_rank(latest_spaces, space_id) |
|
if rank: |
|
space_info = next((s for s in latest_spaces if s['id'] == space_id), None) |
|
if space_info: |
|
html_content += f""" |
|
<div style='margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 8px;'> |
|
<h3>#{rank} - {space_id}</h3> |
|
<p>π Likes: {space_info.get('likes', 'N/A')}</p> |
|
<p>π {space_info.get('title', 'N/A')}</p> |
|
<p>{space_info.get('description', 'N/A')[:100]}...</p> |
|
<a href='{url}' target='_blank' style='color: blue;'>Visit Space π</a> |
|
</div> |
|
""" |
|
|
|
html_content += "</div>" |
|
return html_content |
|
|
|
def export_data(trending_data, dates): |
|
df_data = [] |
|
for date in dates: |
|
spaces = trending_data.get(date, []) |
|
for space_id in target_spaces.keys(): |
|
rank = get_space_rank(spaces, space_id) |
|
if rank: |
|
space_info = next((s for s in spaces if s['id'] == space_id), None) |
|
if space_info: |
|
df_data.append({ |
|
'Date': date, |
|
'Space ID': space_id, |
|
'Rank': rank, |
|
'Likes': space_info.get('likes', 'N/A'), |
|
'Title': space_info.get('title', 'N/A'), |
|
'URL': target_spaces[space_id] |
|
}) |
|
|
|
df = pd.DataFrame(df_data) |
|
return df |
|
|
|
def main_interface(): |
|
trending_data, target_space_ranks, dates = fetch_and_analyze_data() |
|
|
|
|
|
plot = create_trend_plot(trending_data, target_space_ranks, dates) |
|
|
|
|
|
space_info = create_space_info_html(trending_data) |
|
|
|
|
|
df = export_data(trending_data, dates) |
|
|
|
return plot, space_info, df |
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
gr.Markdown("# π€ HuggingFace Spaces Trending Analysis") |
|
|
|
with gr.Tab("Trending Analysis"): |
|
plot_output = gr.Plot() |
|
info_output = gr.HTML() |
|
|
|
with gr.Tab("Export Data"): |
|
df_output = gr.DataFrame() |
|
|
|
refresh_btn = gr.Button("Refresh Data") |
|
refresh_btn.click( |
|
main_interface, |
|
outputs=[plot_output, info_output, df_output] |
|
) |
|
|
|
|
|
plot, info, df = main_interface() |
|
plot_output.update(value=plot) |
|
info_output.update(value=info) |
|
df_output.update(value=df) |
|
|
|
|
|
demo.launch() |