Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,45 @@
|
|
|
|
1 |
import requests
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
from datetime import datetime, timedelta
|
6 |
-
import numpy as np
|
7 |
-
import streamlit as st
|
8 |
import plotly.graph_objects as go
|
9 |
-
import
|
10 |
-
|
11 |
-
import io
|
12 |
-
import base64
|
13 |
-
|
14 |
-
# νμ΄μ§ μ€μ
|
15 |
-
st.set_page_config(layout="wide", page_title="HuggingFace Spaces Trending Analysis")
|
16 |
-
|
17 |
-
# μ€νμΌ μ μ©
|
18 |
-
st.markdown("""
|
19 |
-
<style>
|
20 |
-
.main {
|
21 |
-
background-color: #f5f5f5;
|
22 |
-
}
|
23 |
-
.stButton>button {
|
24 |
-
background-color: #ff4b4b;
|
25 |
-
color: white;
|
26 |
-
border-radius: 5px;
|
27 |
-
}
|
28 |
-
.trending-card {
|
29 |
-
padding: 20px;
|
30 |
-
border-radius: 10px;
|
31 |
-
background-color: white;
|
32 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
33 |
-
margin: 10px 0;
|
34 |
-
}
|
35 |
-
</style>
|
36 |
-
""", unsafe_allow_html=True)
|
37 |
-
|
38 |
-
# νμ΄ν
|
39 |
-
st.title("π€ HuggingFace Spaces Trending Analysis")
|
40 |
|
41 |
# κ΄μ¬ μ€νμ΄μ€ URL 리μ€νΈμ μ 보
|
42 |
target_spaces = {
|
43 |
"ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
|
44 |
"ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
|
45 |
"fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
48 |
}
|
49 |
|
@@ -60,9 +56,7 @@ def get_space_rank(spaces, space_id):
|
|
60 |
return idx
|
61 |
return None
|
62 |
|
63 |
-
|
64 |
-
@st.cache_data
|
65 |
-
def fetch_trending_data():
|
66 |
start_date = datetime(2023, 12, 1)
|
67 |
end_date = datetime(2023, 12, 31)
|
68 |
dates = [(start_date + timedelta(days=x)).strftime('%Y-%m-%d')
|
@@ -71,107 +65,119 @@ def fetch_trending_data():
|
|
71 |
trending_data = {}
|
72 |
target_space_ranks = {space: [] for space in target_spaces.keys()}
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
target_space_ranks[space_id].append(rank)
|
82 |
|
83 |
return trending_data, target_space_ranks, dates
|
84 |
|
85 |
-
trending_data, target_space_ranks, dates
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
'
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
fig.update_layout(
|
106 |
-
title='Trending Ranks Over Time',
|
107 |
-
xaxis_title='Date',
|
108 |
-
yaxis_title='Rank',
|
109 |
-
yaxis_autorange='reversed',
|
110 |
-
height=800,
|
111 |
-
template='plotly_white',
|
112 |
-
hovermode='x unified'
|
113 |
-
)
|
114 |
-
|
115 |
-
st.plotly_chart(fig, use_container_width=True)
|
116 |
-
|
117 |
-
# μ΅μ μμ μ 보 μΆλ ₯
|
118 |
-
st.header("π Latest Rankings")
|
119 |
-
|
120 |
-
latest_date = max(trending_data.keys())
|
121 |
-
latest_spaces = trending_data[latest_date]
|
122 |
-
|
123 |
-
cols = st.columns(3)
|
124 |
-
col_idx = 0
|
125 |
-
|
126 |
-
for space_id, url in target_spaces.items():
|
127 |
-
rank = get_space_rank(latest_spaces, space_id)
|
128 |
-
if rank:
|
129 |
-
space_info = next((s for s in latest_spaces if s['id'] == space_id), None)
|
130 |
-
if space_info:
|
131 |
-
with cols[col_idx % 3]:
|
132 |
-
with st.container():
|
133 |
-
st.markdown(f"""
|
134 |
-
<div class="trending-card">
|
135 |
-
<h3>#{rank} - {space_id}</h3>
|
136 |
-
<p>π Likes: {space_info.get('likes', 'N/A')}</p>
|
137 |
-
<p>π {space_info.get('title', 'N/A')}</p>
|
138 |
-
<p>{space_info.get('description', 'N/A')[:100]}...</p>
|
139 |
-
<a href="{url}" target="_blank">Visit Space π</a>
|
140 |
-
</div>
|
141 |
-
""", unsafe_allow_html=True)
|
142 |
-
col_idx += 1
|
143 |
-
|
144 |
-
# λ€μ΄λ‘λ κΈ°λ₯
|
145 |
-
st.header("π Download Data")
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
153 |
if rank:
|
154 |
-
space_info = next((s for s in
|
155 |
if space_info:
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
'
|
160 |
-
|
161 |
-
|
162 |
-
'
|
163 |
-
|
164 |
-
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
#
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
import seaborn as sns
|
6 |
from datetime import datetime, timedelta
|
|
|
|
|
7 |
import plotly.graph_objects as go
|
8 |
+
import numpy as np
|
9 |
+
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# κ΄μ¬ μ€νμ΄μ€ URL 리μ€νΈμ μ 보
|
12 |
target_spaces = {
|
13 |
"ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
|
14 |
"ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
|
15 |
"fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
|
16 |
+
"fantos/flx8lora": "https://huggingface.co/spaces/fantos/flx8lora",
|
17 |
+
"ginigen/Canvas": "https://huggingface.co/spaces/ginigen/Canvas",
|
18 |
+
"fantaxy/erotica": "https://huggingface.co/spaces/fantaxy/erotica",
|
19 |
+
"ginipick/time-machine": "https://huggingface.co/spaces/ginipick/time-machine",
|
20 |
+
"aiqcamp/FLUX-VisionReply": "https://huggingface.co/spaces/aiqcamp/FLUX-VisionReply",
|
21 |
+
"openfree/Tetris-Game": "https://huggingface.co/spaces/openfree/Tetris-Game",
|
22 |
+
"openfree/everychat": "https://huggingface.co/spaces/openfree/everychat",
|
23 |
+
"VIDraft/mouse1": "https://huggingface.co/spaces/VIDraft/mouse1",
|
24 |
+
"kolaslab/alpha-go": "https://huggingface.co/spaces/kolaslab/alpha-go",
|
25 |
+
"ginipick/text3d": "https://huggingface.co/spaces/ginipick/text3d",
|
26 |
+
"openfree/trending-board": "https://huggingface.co/spaces/openfree/trending-board",
|
27 |
+
"cutechicken/tankwar": "https://huggingface.co/spaces/cutechicken/tankwar",
|
28 |
+
"openfree/game-jewel": "https://huggingface.co/spaces/openfree/game-jewel",
|
29 |
+
"VIDraft/mouse-chat": "https://huggingface.co/spaces/VIDraft/mouse-chat",
|
30 |
+
"ginipick/AccDiffusion": "https://huggingface.co/spaces/ginipick/AccDiffusion",
|
31 |
+
"aiqtech/Particle-Accelerator-Simulation": "https://huggingface.co/spaces/aiqtech/Particle-Accelerator-Simulation",
|
32 |
+
"openfree/GiniGEN": "https://huggingface.co/spaces/openfree/GiniGEN",
|
33 |
+
"kolaslab/3DAudio-Spectrum-Analyzer": "https://huggingface.co/spaces/kolaslab/3DAudio-Spectrum-Analyzer",
|
34 |
+
"openfree/trending-news-24": "https://huggingface.co/spaces/openfree/trending-news-24",
|
35 |
+
"ginipick/Realtime-FLUX": "https://huggingface.co/spaces/ginipick/Realtime-FLUX",
|
36 |
+
"VIDraft/prime-number": "https://huggingface.co/spaces/VIDraft/prime-number",
|
37 |
+
"kolaslab/zombie-game": "https://huggingface.co/spaces/kolaslab/zombie-game",
|
38 |
+
"fantos/miro-game": "https://huggingface.co/spaces/fantos/miro-game",
|
39 |
+
"kolaslab/shooting": "https://huggingface.co/spaces/kolaslab/shooting",
|
40 |
+
"VIDraft/Mouse-Hackathon": "https://huggingface.co/spaces/VIDraft/Mouse-Hackathon",
|
41 |
+
"upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard",
|
42 |
+
"LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo",
|
43 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
44 |
}
|
45 |
|
|
|
56 |
return idx
|
57 |
return None
|
58 |
|
59 |
+
def fetch_and_analyze_data():
|
|
|
|
|
60 |
start_date = datetime(2023, 12, 1)
|
61 |
end_date = datetime(2023, 12, 31)
|
62 |
dates = [(start_date + timedelta(days=x)).strftime('%Y-%m-%d')
|
|
|
65 |
trending_data = {}
|
66 |
target_space_ranks = {space: [] for space in target_spaces.keys()}
|
67 |
|
68 |
+
for date in dates:
|
69 |
+
spaces = get_trending_spaces(date)
|
70 |
+
if spaces:
|
71 |
+
trending_data[date] = spaces
|
72 |
+
for space_id in target_spaces.keys():
|
73 |
+
rank = get_space_rank(spaces, space_id)
|
74 |
+
target_space_ranks[space_id].append(rank)
|
|
|
75 |
|
76 |
return trending_data, target_space_ranks, dates
|
77 |
|
78 |
+
def create_trend_plot(trending_data, target_space_ranks, dates):
|
79 |
+
fig = go.Figure()
|
80 |
+
|
81 |
+
for space_id, ranks in target_space_ranks.items():
|
82 |
+
fig.add_trace(go.Scatter(
|
83 |
+
x=dates,
|
84 |
+
y=ranks,
|
85 |
+
name=space_id,
|
86 |
+
mode='lines+markers'
|
87 |
+
))
|
88 |
+
|
89 |
+
fig.update_layout(
|
90 |
+
title='Trending Ranks Over Time',
|
91 |
+
xaxis_title='Date',
|
92 |
+
yaxis_title='Rank',
|
93 |
+
yaxis_autorange='reversed',
|
94 |
+
height=800
|
95 |
+
)
|
96 |
+
|
97 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
def create_space_info_html(trending_data):
|
100 |
+
latest_date = max(trending_data.keys())
|
101 |
+
latest_spaces = trending_data[latest_date]
|
102 |
+
|
103 |
+
html_content = "<div style='padding: 20px;'>"
|
104 |
+
html_content += f"<h2>Latest Rankings ({latest_date})</h2>"
|
105 |
+
|
106 |
+
for space_id, url in target_spaces.items():
|
107 |
+
rank = get_space_rank(latest_spaces, space_id)
|
108 |
if rank:
|
109 |
+
space_info = next((s for s in latest_spaces if s['id'] == space_id), None)
|
110 |
if space_info:
|
111 |
+
html_content += f"""
|
112 |
+
<div style='margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 8px;'>
|
113 |
+
<h3>#{rank} - {space_id}</h3>
|
114 |
+
<p>π Likes: {space_info.get('likes', 'N/A')}</p>
|
115 |
+
<p>π {space_info.get('title', 'N/A')}</p>
|
116 |
+
<p>{space_info.get('description', 'N/A')[:100]}...</p>
|
117 |
+
<a href='{url}' target='_blank' style='color: blue;'>Visit Space π</a>
|
118 |
+
</div>
|
119 |
+
"""
|
120 |
+
|
121 |
+
html_content += "</div>"
|
122 |
+
return html_content
|
123 |
+
|
124 |
+
def export_data(trending_data, dates):
|
125 |
+
df_data = []
|
126 |
+
for date in dates:
|
127 |
+
spaces = trending_data.get(date, [])
|
128 |
+
for space_id in target_spaces.keys():
|
129 |
+
rank = get_space_rank(spaces, space_id)
|
130 |
+
if rank:
|
131 |
+
space_info = next((s for s in spaces if s['id'] == space_id), None)
|
132 |
+
if space_info:
|
133 |
+
df_data.append({
|
134 |
+
'Date': date,
|
135 |
+
'Space ID': space_id,
|
136 |
+
'Rank': rank,
|
137 |
+
'Likes': space_info.get('likes', 'N/A'),
|
138 |
+
'Title': space_info.get('title', 'N/A'),
|
139 |
+
'URL': target_spaces[space_id]
|
140 |
+
})
|
141 |
+
|
142 |
+
df = pd.DataFrame(df_data)
|
143 |
+
return df
|
144 |
|
145 |
+
def main_interface():
|
146 |
+
trending_data, target_space_ranks, dates = fetch_and_analyze_data()
|
147 |
+
|
148 |
+
# νΈλ λ νλ‘― μμ±
|
149 |
+
plot = create_trend_plot(trending_data, target_space_ranks, dates)
|
150 |
+
|
151 |
+
# μ€νμ΄μ€ μ 보 HTML μμ±
|
152 |
+
space_info = create_space_info_html(trending_data)
|
153 |
+
|
154 |
+
# λ°μ΄ν° μ΅μ€ν¬νΈ
|
155 |
+
df = export_data(trending_data, dates)
|
156 |
+
|
157 |
+
return plot, space_info, df
|
158 |
|
159 |
+
# Gradio μΈν°νμ΄μ€ μμ±
|
160 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
161 |
+
gr.Markdown("# π€ HuggingFace Spaces Trending Analysis")
|
162 |
+
|
163 |
+
with gr.Tab("Trending Analysis"):
|
164 |
+
plot_output = gr.Plot()
|
165 |
+
info_output = gr.HTML()
|
166 |
+
|
167 |
+
with gr.Tab("Export Data"):
|
168 |
+
df_output = gr.DataFrame()
|
169 |
+
|
170 |
+
refresh_btn = gr.Button("Refresh Data")
|
171 |
+
refresh_btn.click(
|
172 |
+
main_interface,
|
173 |
+
outputs=[plot_output, info_output, df_output]
|
174 |
+
)
|
175 |
+
|
176 |
+
# μ΄κΈ° λ°μ΄ν° λ‘λ
|
177 |
+
plot, info, df = main_interface()
|
178 |
+
plot_output.update(value=plot)
|
179 |
+
info_output.update(value=info)
|
180 |
+
df_output.update(value=df)
|
181 |
+
|
182 |
+
# Gradio μ± μ€ν
|
183 |
+
demo.launch()
|