Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ target_spaces = {
|
|
42 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
43 |
}
|
44 |
|
45 |
-
def get_trending_spaces(
|
46 |
"""νΈλ λ© μ€νμ΄μ€ κ°μ Έμ€κΈ°"""
|
47 |
url = "https://huggingface.co/api/spaces"
|
48 |
|
@@ -50,22 +50,64 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
|
|
50 |
progress(0, desc="Fetching spaces data...")
|
51 |
params = {
|
52 |
'full': 'true',
|
53 |
-
'limit':
|
54 |
}
|
55 |
|
56 |
response = requests.get(url, params=params)
|
57 |
response.raise_for_status()
|
58 |
all_spaces = response.json()
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# νΈλ λ μκ°ν μμ±
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# μ€νμ΄μ€ μΉ΄λ HTML μμ±
|
71 |
html_content = """
|
@@ -73,8 +115,9 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
|
|
73 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
74 |
"""
|
75 |
|
76 |
-
for
|
77 |
space_id = space.get('id', '')
|
|
|
78 |
likes = space.get('likes', 0)
|
79 |
title = space.get('title', 'No Title')
|
80 |
description = space.get('description', 'No Description')[:100]
|
@@ -87,7 +130,7 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
|
|
87 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
88 |
transition: transform 0.2s;
|
89 |
'>
|
90 |
-
<h3 style='color: #34495e;'
|
91 |
<p style='color: #7f8c8d;'>π Likes: {likes}</p>
|
92 |
<p style='color: #2c3e50;'>{title}</p>
|
93 |
<p style='color: #7f8c8d; font-size: 0.9em;'>{description}...</p>
|
@@ -106,21 +149,30 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
|
|
106 |
</a>
|
107 |
</div>
|
108 |
"""
|
109 |
-
progress((0.
|
110 |
-
|
|
|
111 |
html_content += "</div></div>"
|
112 |
|
113 |
# λ°μ΄ν° ν
μ΄λΈ μμ±
|
114 |
-
df =
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
progress(1.0, desc="Complete!")
|
117 |
-
return
|
118 |
|
119 |
except Exception as e:
|
120 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
121 |
error_plot = create_error_plot()
|
122 |
return error_plot, error_html, pd.DataFrame()
|
123 |
|
|
|
|
|
124 |
def create_trend_visualization(spaces_data):
|
125 |
if not spaces_data:
|
126 |
return create_error_plot()
|
|
|
42 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
43 |
}
|
44 |
|
45 |
+
def get_trending_spaces(progress=gr.Progress()):
|
46 |
"""νΈλ λ© μ€νμ΄μ€ κ°μ Έμ€κΈ°"""
|
47 |
url = "https://huggingface.co/api/spaces"
|
48 |
|
|
|
50 |
progress(0, desc="Fetching spaces data...")
|
51 |
params = {
|
52 |
'full': 'true',
|
53 |
+
'limit': 300 # μμ 300κ° μ€νμ΄μ€ κ°μ Έμ€κΈ°
|
54 |
}
|
55 |
|
56 |
response = requests.get(url, params=params)
|
57 |
response.raise_for_status()
|
58 |
all_spaces = response.json()
|
59 |
|
60 |
+
# λͺ¨λ μ€νμ΄μ€μ μμ μ 보 μ μ₯
|
61 |
+
space_ranks = {space['id']: idx + 1 for idx, space in enumerate(all_spaces)}
|
62 |
|
63 |
+
# target_spacesμ μλ μ€νμ΄μ€λ§ νν°λ§νκ³ μ€μ μμ μ 보 ν¬ν¨
|
64 |
+
spaces = []
|
65 |
+
for space in all_spaces:
|
66 |
+
if space.get('id', '') in target_spaces:
|
67 |
+
space['rank'] = space_ranks.get(space['id'], 'N/A')
|
68 |
+
spaces.append(space)
|
69 |
+
|
70 |
+
# μμλ³λ‘ μ λ ¬
|
71 |
+
spaces.sort(key=lambda x: x['rank'])
|
72 |
+
|
73 |
+
progress(0.3, desc="Creating visualization...")
|
74 |
|
75 |
# νΈλ λ μκ°ν μμ±
|
76 |
+
fig = go.Figure()
|
77 |
+
|
78 |
+
# μμ λ°μ΄ν° μ€λΉ
|
79 |
+
ids = [space['id'] for space in spaces]
|
80 |
+
ranks = [space['rank'] for space in spaces]
|
81 |
+
likes = [space.get('likes', 0) for space in spaces]
|
82 |
+
|
83 |
+
# λ§λ κ·Έλν μμ±
|
84 |
+
fig.add_trace(go.Bar(
|
85 |
+
x=ids,
|
86 |
+
y=ranks,
|
87 |
+
text=[f"Rank: {r}<br>Likes: {l}" for r, l in zip(ranks, likes)],
|
88 |
+
textposition='auto',
|
89 |
+
marker_color='rgb(158,202,225)',
|
90 |
+
opacity=0.8
|
91 |
+
))
|
92 |
|
93 |
+
fig.update_layout(
|
94 |
+
title={
|
95 |
+
'text': 'Hugging Face Spaces Rankings (Top 300)',
|
96 |
+
'y':0.95,
|
97 |
+
'x':0.5,
|
98 |
+
'xanchor': 'center',
|
99 |
+
'yanchor': 'top'
|
100 |
+
},
|
101 |
+
xaxis_title='Space ID',
|
102 |
+
yaxis_title='Rank',
|
103 |
+
yaxis_autorange='reversed', # μμκ° μμμ μλλ‘ λ΄λ €κ°λλ‘
|
104 |
+
height=800,
|
105 |
+
showlegend=False,
|
106 |
+
template='plotly_white',
|
107 |
+
xaxis_tickangle=-45
|
108 |
+
)
|
109 |
+
|
110 |
+
progress(0.6, desc="Creating space cards...")
|
111 |
|
112 |
# μ€νμ΄μ€ μΉ΄λ HTML μμ±
|
113 |
html_content = """
|
|
|
115 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
116 |
"""
|
117 |
|
118 |
+
for space in spaces:
|
119 |
space_id = space.get('id', '')
|
120 |
+
rank = space.get('rank', 'N/A')
|
121 |
likes = space.get('likes', 0)
|
122 |
title = space.get('title', 'No Title')
|
123 |
description = space.get('description', 'No Description')[:100]
|
|
|
130 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
131 |
transition: transform 0.2s;
|
132 |
'>
|
133 |
+
<h3 style='color: #34495e;'>Rank #{rank} - {space_id}</h3>
|
134 |
<p style='color: #7f8c8d;'>π Likes: {likes}</p>
|
135 |
<p style='color: #2c3e50;'>{title}</p>
|
136 |
<p style='color: #7f8c8d; font-size: 0.9em;'>{description}...</p>
|
|
|
149 |
</a>
|
150 |
</div>
|
151 |
"""
|
152 |
+
progress((0.6 + 0.3 * spaces.index(space)/len(spaces)),
|
153 |
+
desc=f"Loading space {spaces.index(space)+1}/{len(spaces)}...")
|
154 |
+
|
155 |
html_content += "</div></div>"
|
156 |
|
157 |
# λ°μ΄ν° ν
μ΄λΈ μμ±
|
158 |
+
df = pd.DataFrame([{
|
159 |
+
'Rank': space.get('rank', 'N/A'),
|
160 |
+
'Space ID': space.get('id', ''),
|
161 |
+
'Likes': space.get('likes', 'N/A'),
|
162 |
+
'Title': space.get('title', 'N/A'),
|
163 |
+
'URL': target_spaces[space.get('id', '')]
|
164 |
+
} for space in spaces])
|
165 |
|
166 |
progress(1.0, desc="Complete!")
|
167 |
+
return fig, html_content, df
|
168 |
|
169 |
except Exception as e:
|
170 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
171 |
error_plot = create_error_plot()
|
172 |
return error_plot, error_html, pd.DataFrame()
|
173 |
|
174 |
+
# Gradio μΈν°νμ΄μ€λ μ΄μ κ³Ό λμΌ
|
175 |
+
|
176 |
def create_trend_visualization(spaces_data):
|
177 |
if not spaces_data:
|
178 |
return create_error_plot()
|