Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -42,41 +42,84 @@ target_spaces = {
|
|
42 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
43 |
}
|
44 |
|
45 |
-
def get_trending_spaces():
|
|
|
|
|
|
|
46 |
try:
|
47 |
-
|
48 |
-
url = "https://huggingface.co/api/spaces/trending"
|
49 |
-
|
50 |
-
headers = {
|
51 |
-
'Authorization': f'Bearer {HF_TOKEN}',
|
52 |
-
'Accept': 'application/json',
|
53 |
-
'User-Agent': 'Mozilla/5.0'
|
54 |
-
}
|
55 |
-
|
56 |
-
# ๋ชจ๋ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด limit ์ฆ๊ฐ
|
57 |
params = {
|
58 |
-
'
|
59 |
-
'
|
60 |
}
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
if response.status_code == 200:
|
65 |
-
data = response.json()
|
66 |
-
# target_spaces์ ์๋ ์คํ์ด์ค๋ง ํํฐ๋ง
|
67 |
-
filtered_data = []
|
68 |
-
for space in data:
|
69 |
-
space_id = space.get('id', '')
|
70 |
-
if space_id in target_spaces:
|
71 |
-
filtered_data.append(space)
|
72 |
-
return filtered_data
|
73 |
-
else:
|
74 |
-
print(f"API ์์ฒญ ์คํจ: {response.status_code}")
|
75 |
-
print(f"Response: {response.text}")
|
76 |
-
return None
|
77 |
except Exception as e:
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
def create_trend_visualization(spaces_data):
|
82 |
if not spaces_data:
|
@@ -299,22 +342,24 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
299 |
df_output = gr.DataFrame()
|
300 |
|
301 |
refresh_btn = gr.Button("๐ Refresh Data", variant="primary")
|
|
|
|
|
|
|
|
|
302 |
refresh_btn.click(
|
303 |
refresh_data,
|
304 |
outputs=[plot_output, info_output, df_output]
|
305 |
)
|
306 |
|
307 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
308 |
-
initial_plot, initial_info, initial_df =
|
309 |
plot_output.value = initial_plot
|
310 |
info_output.value = initial_info
|
311 |
df_output.value = initial_df
|
312 |
|
313 |
# Gradio ์ฑ ์คํ
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
debug=True
|
320 |
-
)
|
|
|
42 |
"NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
|
43 |
}
|
44 |
|
45 |
+
def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress()):
|
46 |
+
"""ํธ๋ ๋ฉ ์คํ์ด์ค ๊ฐ์ ธ์ค๊ธฐ"""
|
47 |
+
url = "https://huggingface.co/api/spaces"
|
48 |
+
|
49 |
try:
|
50 |
+
progress(0, desc="Fetching spaces data...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
params = {
|
52 |
+
'full': 'true',
|
53 |
+
'limit': 1000 # ์ถฉ๋ถํ ์์ ์คํ์ด์ค๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด ์ฆ๊ฐ
|
54 |
}
|
55 |
+
|
56 |
+
response = requests.get(url, params=params)
|
57 |
+
response.raise_for_status()
|
58 |
+
all_spaces = response.json()
|
59 |
|
60 |
+
# target_spaces์ ์๋ ์คํ์ด์ค๋ง ํํฐ๋ง
|
61 |
+
spaces = [space for space in all_spaces if space.get('id', '') in target_spaces]
|
62 |
+
|
63 |
+
progress(0.1, desc="Creating visualization...")
|
64 |
+
|
65 |
+
# ํธ๋ ๋ ์๊ฐํ ์์ฑ
|
66 |
+
plot = create_trend_visualization(spaces)
|
67 |
+
|
68 |
+
progress(0.4, desc="Creating space cards...")
|
69 |
+
|
70 |
+
# ์คํ์ด์ค ์นด๋ HTML ์์ฑ
|
71 |
+
html_content = """
|
72 |
+
<div style='padding: 20px; background: #f5f5f5;'>
|
73 |
+
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
74 |
+
"""
|
75 |
+
|
76 |
+
for idx, space in enumerate(spaces):
|
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]
|
81 |
+
|
82 |
+
html_content += f"""
|
83 |
+
<div style='
|
84 |
+
background: white;
|
85 |
+
padding: 20px;
|
86 |
+
border-radius: 10px;
|
87 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
88 |
+
transition: transform 0.2s;
|
89 |
+
'>
|
90 |
+
<h3 style='color: #34495e;'>#{idx + 1} - {space_id}</h3>
|
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>
|
94 |
+
<a href='{target_spaces[space_id]}'
|
95 |
+
target='_blank'
|
96 |
+
style='
|
97 |
+
display: inline-block;
|
98 |
+
padding: 8px 16px;
|
99 |
+
background: #3498db;
|
100 |
+
color: white;
|
101 |
+
text-decoration: none;
|
102 |
+
border-radius: 5px;
|
103 |
+
transition: background 0.3s;
|
104 |
+
'>
|
105 |
+
Visit Space ๐
|
106 |
+
</a>
|
107 |
+
</div>
|
108 |
+
"""
|
109 |
+
progress((0.4 + 0.5 * idx/len(spaces)), desc=f"Loading space {idx+1}/{len(spaces)}...")
|
110 |
+
|
111 |
+
html_content += "</div></div>"
|
112 |
+
|
113 |
+
# ๋ฐ์ดํฐ ํ
์ด๋ธ ์์ฑ
|
114 |
+
df = create_data_table(spaces)
|
115 |
+
|
116 |
+
progress(1.0, desc="Complete!")
|
117 |
+
return plot, html_content, df
|
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:
|
|
|
342 |
df_output = gr.DataFrame()
|
343 |
|
344 |
refresh_btn = gr.Button("๐ Refresh Data", variant="primary")
|
345 |
+
|
346 |
+
def refresh_data():
|
347 |
+
return get_trending_spaces()
|
348 |
+
|
349 |
refresh_btn.click(
|
350 |
refresh_data,
|
351 |
outputs=[plot_output, info_output, df_output]
|
352 |
)
|
353 |
|
354 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
|
355 |
+
initial_plot, initial_info, initial_df = get_trending_spaces()
|
356 |
plot_output.value = initial_plot
|
357 |
info_output.value = initial_info
|
358 |
df_output.value = initial_df
|
359 |
|
360 |
# Gradio ์ฑ ์คํ
|
361 |
+
demo.launch(
|
362 |
+
server_name="0.0.0.0",
|
363 |
+
server_port=7860,
|
364 |
+
share=False
|
365 |
+
)
|
|
|
|