Spaces:
Running
Running
File size: 11,726 Bytes
486004a c26f143 e195ac6 a9e3b8d c26f143 486004a c26f143 62fc2dd 8ffa15c e44e7ed a9e3b8d 62fc2dd e195ac6 e44e7ed 62fc2dd a9e3b8d e44e7ed a9e3b8d e44e7ed a9e3b8d 62fc2dd 8ffa15c e44e7ed 8ffa15c 62fc2dd 8ffa15c c26f143 62fc2dd 8ffa15c 486004a e44e7ed 62fc2dd fb8428f e44e7ed 62fc2dd e195ac6 62fc2dd e44e7ed 62fc2dd e44e7ed 62fc2dd e44e7ed 62fc2dd e195ac6 e44e7ed 62fc2dd 486004a e195ac6 e44e7ed e195ac6 62fc2dd e44e7ed 486004a fb8428f e195ac6 fb8428f 486004a c26f143 e44e7ed fb8428f 62fc2dd 8ffa15c e195ac6 e44e7ed e195ac6 62fc2dd e44e7ed 62fc2dd e195ac6 e44e7ed e195ac6 e44e7ed e195ac6 62fc2dd e195ac6 62fc2dd 8ffa15c 62fc2dd 8ffa15c 486004a 62fc2dd c26f143 62fc2dd e195ac6 c26f143 486004a e195ac6 486004a e195ac6 486004a 8ffa15c 486004a 62fc2dd 486004a a9e3b8d |
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
import gradio as gr
import requests
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime
import os
HF_TOKEN = os.getenv("HF_TOKEN")
# ๊ด์ฌ ์คํ์ด์ค 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():
try:
# ํธ๋ ๋ฉ API ์๋ํฌ์ธํธ ์์
url = "https://huggingface.co/api/spaces/trending"
headers = {
'Authorization': f'Bearer {HF_TOKEN}',
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0'
}
# ๋ชจ๋ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด limit ์ฆ๊ฐ
params = {
'limit': 5000, # ์ต๋ํ ๋ง์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ
'interval': 'day' # ์ผ๊ฐ ํธ๋ ๋ฉ
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
# target_spaces์ ์๋ ์คํ์ด์ค๋ง ํํฐ๋ง
filtered_data = []
for space in data:
space_id = space.get('id', '')
if space_id in target_spaces:
filtered_data.append(space)
return filtered_data
else:
print(f"API ์์ฒญ ์คํจ: {response.status_code}")
print(f"Response: {response.text}")
return None
except Exception as e:
print(f"API ํธ์ถ ์ค ์๋ฌ ๋ฐ์: {str(e)}")
return None
def create_trend_visualization(spaces_data):
if not spaces_data:
return create_error_plot()
fig = go.Figure()
# ์์ ๋ฐ์ดํฐ ์ค๋น
ranks = []
for idx, space in enumerate(spaces_data, 1):
space_id = space.get('id', '')
if space_id in target_spaces:
ranks.append({
'id': space_id,
'rank': idx,
'likes': space.get('likes', 0),
'title': space.get('title', 'N/A'),
'views': space.get('views', 0)
})
if not ranks:
return create_error_plot()
# ์์๋ณ๋ก ์ ๋ ฌ
ranks.sort(key=lambda x: x['rank'])
# ํ๋กฏ ๋ฐ์ดํฐ ์์ฑ
ids = [r['id'] for r in ranks]
rank_values = [r['rank'] for r in ranks]
likes = [r['likes'] for r in ranks]
views = [r['views'] for r in ranks]
# ๋ง๋ ๊ทธ๋ํ ์์ฑ
fig.add_trace(go.Bar(
x=ids,
y=rank_values,
text=[f"Rank: {r}<br>Likes: {l}<br>Views: {v}" for r, l, v in zip(rank_values, likes, views)],
textposition='auto',
marker_color='rgb(158,202,225)',
opacity=0.8
))
fig.update_layout(
title={
'text': 'Current Trending Ranks (All Target Spaces)',
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'
},
xaxis_title='Space ID',
yaxis_title='Trending Rank',
yaxis_autorange='reversed',
height=800,
showlegend=False,
template='plotly_white',
xaxis_tickangle=-45
)
return fig
# ํ ํฐ์ด ์๋ ๊ฒฝ์ฐ๋ฅผ ์ํ ๋์ฒด ํจ์
def get_trending_spaces_without_token():
try:
url = "https://huggingface.co/api/spaces"
params = {
'sort': 'likes',
'direction': -1,
'limit': 1000,
'full': 'true'
}
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"API ์์ฒญ ์คํจ (ํ ํฐ ์์): {response.status_code}")
print(f"Response: {response.text}")
return None
except Exception as e:
print(f"API ํธ์ถ ์ค ์๋ฌ ๋ฐ์ (ํ ํฐ ์์): {str(e)}")
return None
# API ํ ํฐ ์ค์ ๋ฐ ํจ์ ์ ํ
if not HF_TOKEN:
get_trending_spaces = get_trending_spaces_without_token
def create_error_plot():
fig = go.Figure()
fig.add_annotation(
text="๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.\n(API ์ธ์ฆ์ด ํ์ํฉ๋๋ค)",
xref="paper",
yref="paper",
x=0.5,
y=0.5,
showarrow=False,
font=dict(size=20)
)
fig.update_layout(
title="Error Loading Data",
height=400
)
return fig
def create_space_info_html(spaces_data):
if not spaces_data:
return "<div style='padding: 20px;'><h2>๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค.</h2></div>"
html_content = """
<div style='padding: 20px;'>
<h2 style='color: #2c3e50;'>Current Trending Rankings</h2>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
"""
# ๋ชจ๋ target spaces๋ฅผ ํฌํจํ๋๋ก ์์
for space_id in target_spaces.keys():
space_info = next((s for s in spaces_data if s.get('id') == space_id), None)
if space_info:
rank = next((idx for idx, s in enumerate(spaces_data, 1) if s.get('id') == space_id), 'N/A')
html_content += f"""
<div style='
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: transform 0.2s;
'>
<h3 style='color: #34495e;'>#{rank} - {space_id}</h3>
<p style='color: #7f8c8d;'>๐ Likes: {space_info.get('likes', 'N/A')}</p>
<p style='color: #7f8c8d;'>๐ Views: {space_info.get('views', 'N/A')}</p>
<p style='color: #2c3e50;'>{space_info.get('title', 'N/A')}</p>
<p style='color: #7f8c8d; font-size: 0.9em;'>{space_info.get('description', 'N/A')[:100]}...</p>
<a href='{target_spaces[space_id]}'
target='_blank'
style='
display: inline-block;
padding: 8px 16px;
background: #3498db;
color: white;
text-decoration: none;
border-radius: 5px;
transition: background 0.3s;
'>
Visit Space ๐
</a>
</div>
"""
else:
html_content += f"""
<div style='
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
'>
<h3 style='color: #34495e;'>{space_id}</h3>
<p style='color: #7f8c8d;'>Not in trending</p>
<a href='{target_spaces[space_id]}'
target='_blank'
style='
display: inline-block;
padding: 8px 16px;
background: #95a5a6;
color: white;
text-decoration: none;
border-radius: 5px;
'>
Visit Space ๐
</a>
</div>
"""
html_content += "</div></div>"
return html_content
def create_data_table(spaces_data):
if not spaces_data:
return pd.DataFrame()
rows = []
for idx, space in enumerate(spaces_data, 1):
space_id = space.get('id', '')
if space_id in target_spaces:
rows.append({
'Rank': idx,
'Space ID': space_id,
'Likes': space.get('likes', 'N/A'),
'Title': space.get('title', 'N/A'),
'URL': target_spaces[space_id]
})
return pd.DataFrame(rows)
def refresh_data():
spaces_data = get_trending_spaces()
if spaces_data:
plot = create_trend_visualization(spaces_data)
info = create_space_info_html(spaces_data)
df = create_data_table(spaces_data)
return plot, info, df
else:
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ์ํฉ๋๋ค.</div>", pd.DataFrame()
# Gradio ์ธํฐํ์ด์ค ์์ฑ
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# ๐ค HuggingFace Spaces Trending Analysis
์ค์๊ฐ์ผ๋ก Hugging Face Spaces์ ํธ๋ ๋ฉ ์์๋ฅผ ๋ถ์ํฉ๋๋ค.
""")
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", variant="primary")
refresh_btn.click(
refresh_data,
outputs=[plot_output, info_output, df_output]
)
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
initial_plot, initial_info, initial_df = refresh_data()
plot_output.value = initial_plot
info_output.value = initial_info
df_output.value = initial_df
# Gradio ์ฑ ์คํ
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False, # True๋ก ์ค์ ํ๋ฉด ๊ณต๊ฐ ๋งํฌ ์์ฑ
debug=True
) |