Spaces:
Running
Running
File size: 7,424 Bytes
486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a c26f143 486004a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
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
# κ΄μ¬ μ€νμ΄μ€ URL 리μ€νΈμ μ 보
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)
# μ€νμ΄μ€ μ 보 HTML μμ±
space_info = create_space_info_html(trending_data)
# λ°μ΄ν° μ΅μ€ν¬νΈ
df = export_data(trending_data, dates)
return plot, space_info, df
# Gradio μΈν°νμ΄μ€ μμ±
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)
# Gradio μ± μ€ν
demo.launch() |