Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -291,8 +291,6 @@ target_models = {
|
|
291 |
"sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
|
292 |
}
|
293 |
|
294 |
-
# all_models ๊ด๋ จ ์ฝ๋ ์ ๊ฑฐํ๊ณ get_models_data ํจ์ ๋ด๋ถ์์ ์ฒ๋ฆฌํ๋๋ก ์์
|
295 |
-
|
296 |
def get_models_data(progress=gr.Progress()):
|
297 |
"""๋ชจ๋ธ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ"""
|
298 |
def normalize_model_id(model_id):
|
@@ -303,44 +301,43 @@ def get_models_data(progress=gr.Progress()):
|
|
303 |
|
304 |
try:
|
305 |
progress(0, desc="Fetching models data...")
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
-
|
308 |
-
all_found_models = []
|
309 |
-
sort_options = [
|
310 |
-
{'sort': 'downloads', 'direction': -1},
|
311 |
-
{'sort': 'lastModified', 'direction': -1},
|
312 |
-
{'sort': 'likes', 'direction': -1}
|
313 |
-
]
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
}
|
321 |
-
|
322 |
-
headers = {'Accept': 'application/json'}
|
323 |
-
|
324 |
-
response = requests.get(url, params=params, headers=headers)
|
325 |
-
if response.status_code == 200:
|
326 |
-
models = response.json()
|
327 |
-
all_found_models.extend(models)
|
328 |
|
329 |
-
#
|
330 |
-
seen_ids = set()
|
331 |
filtered_models = []
|
332 |
-
for model in
|
333 |
model_id = normalize_model_id(model.get('id', ''))
|
334 |
-
if model_id
|
335 |
-
|
336 |
filtered_models.append(model)
|
337 |
|
338 |
-
#
|
339 |
-
filtered_models.sort(key=lambda x: x
|
340 |
-
|
341 |
-
# ์์ ํ ๋น
|
342 |
-
for idx, model in enumerate(filtered_models, 1):
|
343 |
-
model['rank'] = idx
|
344 |
|
345 |
if not filtered_models:
|
346 |
return create_error_plot(), "<div>์ ํ๋ ๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.</div>", pd.DataFrame()
|
@@ -363,7 +360,7 @@ def get_models_data(progress=gr.Progress()):
|
|
363 |
fig.add_trace(go.Bar(
|
364 |
x=ids,
|
365 |
y=y_values,
|
366 |
-
text=[f"Rank: {r}<br>Likes: {l}<br>Downloads: {d}"
|
367 |
for r, l, d in zip(ranks, likes, downloads)],
|
368 |
textposition='auto',
|
369 |
marker_color='rgb(158,202,225)',
|
@@ -372,14 +369,14 @@ def get_models_data(progress=gr.Progress()):
|
|
372 |
|
373 |
fig.update_layout(
|
374 |
title={
|
375 |
-
'text': 'Hugging Face Models
|
376 |
'y':0.95,
|
377 |
'x':0.5,
|
378 |
'xanchor': 'center',
|
379 |
'yanchor': 'top'
|
380 |
},
|
381 |
xaxis_title='Model ID',
|
382 |
-
yaxis_title='Rank',
|
383 |
yaxis=dict(
|
384 |
ticktext=[str(i) for i in range(1, 1001, 50)],
|
385 |
tickvals=[1001 - i for i in range(1, 1001, 50)],
|
@@ -396,7 +393,7 @@ def get_models_data(progress=gr.Progress()):
|
|
396 |
# HTML ์นด๋ ์์ฑ
|
397 |
html_content = """
|
398 |
<div style='padding: 20px; background: #f5f5f5;'>
|
399 |
-
<h2 style='color: #2c3e50;'>Models
|
400 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
401 |
"""
|
402 |
|
@@ -415,9 +412,9 @@ def get_models_data(progress=gr.Progress()):
|
|
415 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
416 |
transition: transform 0.2s;
|
417 |
'>
|
418 |
-
<h3 style='color: #34495e;'>Rank #{rank} - {model_id}</h3>
|
419 |
-
<p style='color: #7f8c8d;'>๐ Likes: {likes}</p>
|
420 |
-
<p style='color: #7f8c8d;'>โฌ๏ธ Downloads: {downloads}</p>
|
421 |
<a href='{target_models[model_id]}'
|
422 |
target='_blank'
|
423 |
style='
|
@@ -445,7 +442,7 @@ def get_models_data(progress=gr.Progress()):
|
|
445 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
446 |
'>
|
447 |
<h3 style='color: #34495e;'>{model_id}</h3>
|
448 |
-
<p style='color: #7f8c8d;'>Not in top 1000</p>
|
449 |
<a href='{target_models[model_id]}'
|
450 |
target='_blank'
|
451 |
style='
|
@@ -468,17 +465,17 @@ def get_models_data(progress=gr.Progress()):
|
|
468 |
# ์์๊ถ ๋ด ๋ชจ๋ธ
|
469 |
for model in filtered_models:
|
470 |
df_data.append({
|
471 |
-
'Rank': model['rank'],
|
472 |
'Model ID': model['id'],
|
473 |
-
'Likes': model.get('likes',
|
474 |
-
'Downloads': model.get('downloads',
|
475 |
'URL': target_models[model['id']]
|
476 |
})
|
477 |
# ์์๊ถ ๋ฐ ๋ชจ๋ธ
|
478 |
for model_id in target_models:
|
479 |
if model_id not in [m['id'] for m in filtered_models]:
|
480 |
df_data.append({
|
481 |
-
'Rank': 'Not in top 1000',
|
482 |
'Model ID': model_id,
|
483 |
'Likes': 'N/A',
|
484 |
'Downloads': 'N/A',
|
@@ -877,13 +874,15 @@ def refresh_data():
|
|
877 |
else:
|
878 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ์ํฉ๋๋ค.</div>", pd.DataFrame()
|
879 |
|
880 |
-
|
881 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
882 |
gr.Markdown("""
|
883 |
# ๐ค ํ๊น
ํ์ด์ค 'ํ๊ตญ ๋ฆฌ๋๋ณด๋'
|
884 |
์ค์๊ฐ์ผ๋ก Hugging Face์ Spaces์ Models ์ธ๊ธฐ ์์๋ฅผ ๋ถ์ํฉ๋๋ค. ์ ๊ท ๋ฑ๋ก ์์ฒญ: arxivgpt@gmail.com
|
885 |
""")
|
886 |
|
|
|
|
|
|
|
887 |
with gr.Tab("Spaces Trending"):
|
888 |
trending_plot = gr.Plot()
|
889 |
trending_info = gr.HTML()
|
@@ -894,8 +893,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
894 |
models_info = gr.HTML()
|
895 |
models_df = gr.DataFrame()
|
896 |
|
897 |
-
refresh_btn = gr.Button("๐ Refresh Data", variant="primary")
|
898 |
-
|
899 |
def refresh_all_data():
|
900 |
spaces_results = get_spaces_data("trending")
|
901 |
models_results = get_models_data()
|
@@ -916,6 +913,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
916 |
trending_plot.value, trending_info.value, trending_df.value = spaces_results
|
917 |
models_plot.value, models_info.value, models_df.value = models_results
|
918 |
|
|
|
919 |
# Gradio ์ฑ ์คํ
|
920 |
demo.launch(
|
921 |
server_name="0.0.0.0",
|
|
|
291 |
"sel303/llama3-diverce-ver1.6": "https://huggingface.co/sel303/llama3-diverce-ver1.6"
|
292 |
}
|
293 |
|
|
|
|
|
294 |
def get_models_data(progress=gr.Progress()):
|
295 |
"""๋ชจ๋ธ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ"""
|
296 |
def normalize_model_id(model_id):
|
|
|
301 |
|
302 |
try:
|
303 |
progress(0, desc="Fetching models data...")
|
304 |
+
params = {
|
305 |
+
'full': 'true',
|
306 |
+
'limit': 1000,
|
307 |
+
'sort': 'downloads',
|
308 |
+
'direction': -1
|
309 |
+
}
|
310 |
|
311 |
+
headers = {'Accept': 'application/json'}
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
+
response = requests.get(url, params=params, headers=headers)
|
314 |
+
if response.status_code != 200:
|
315 |
+
print(f"API ์์ฒญ ์คํจ: {response.status_code}")
|
316 |
+
print(f"Response: {response.text}")
|
317 |
+
return create_error_plot(), "<div>๋ชจ๋ธ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์คํจํ์ต๋๋ค.</div>", pd.DataFrame()
|
318 |
+
|
319 |
+
models = response.json()
|
320 |
+
|
321 |
+
# ์ ์ฒด ์์ ์ ๋ณด ์ ์ฅ (๋ค์ด๋ก๋ ์ ๊ธฐ์ค)
|
322 |
+
model_ranks = {}
|
323 |
+
for idx, model in enumerate(models, 1):
|
324 |
+
model_id = normalize_model_id(model.get('id', ''))
|
325 |
+
model_ranks[model_id] = {
|
326 |
+
'rank': idx,
|
327 |
+
'downloads': model.get('downloads', 0),
|
328 |
+
'likes': model.get('likes', 0)
|
329 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
|
331 |
+
# target_models ์ค ์์๊ถ ๋ด ๋ชจ๋ธ ํํฐ๋ง
|
|
|
332 |
filtered_models = []
|
333 |
+
for model in models:
|
334 |
model_id = normalize_model_id(model.get('id', ''))
|
335 |
+
if model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
|
336 |
+
model['rank'] = model_ranks[model_id]['rank']
|
337 |
filtered_models.append(model)
|
338 |
|
339 |
+
# ์์๋ก ์ ๋ ฌ
|
340 |
+
filtered_models.sort(key=lambda x: x['rank'])
|
|
|
|
|
|
|
|
|
341 |
|
342 |
if not filtered_models:
|
343 |
return create_error_plot(), "<div>์ ํ๋ ๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.</div>", pd.DataFrame()
|
|
|
360 |
fig.add_trace(go.Bar(
|
361 |
x=ids,
|
362 |
y=y_values,
|
363 |
+
text=[f"Global Rank: {r}<br>Likes: {l:,}<br>Downloads: {d:,}"
|
364 |
for r, l, d in zip(ranks, likes, downloads)],
|
365 |
textposition='auto',
|
366 |
marker_color='rgb(158,202,225)',
|
|
|
369 |
|
370 |
fig.update_layout(
|
371 |
title={
|
372 |
+
'text': 'Hugging Face Models Global Download Rankings (Top 1000)',
|
373 |
'y':0.95,
|
374 |
'x':0.5,
|
375 |
'xanchor': 'center',
|
376 |
'yanchor': 'top'
|
377 |
},
|
378 |
xaxis_title='Model ID',
|
379 |
+
yaxis_title='Global Rank',
|
380 |
yaxis=dict(
|
381 |
ticktext=[str(i) for i in range(1, 1001, 50)],
|
382 |
tickvals=[1001 - i for i in range(1, 1001, 50)],
|
|
|
393 |
# HTML ์นด๋ ์์ฑ
|
394 |
html_content = """
|
395 |
<div style='padding: 20px; background: #f5f5f5;'>
|
396 |
+
<h2 style='color: #2c3e50;'>Models Global Download Rankings</h2>
|
397 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
398 |
"""
|
399 |
|
|
|
412 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
413 |
transition: transform 0.2s;
|
414 |
'>
|
415 |
+
<h3 style='color: #34495e;'>Global Rank #{rank} - {model_id}</h3>
|
416 |
+
<p style='color: #7f8c8d;'>๐ Likes: {likes:,}</p>
|
417 |
+
<p style='color: #7f8c8d;'>โฌ๏ธ Downloads: {downloads:,}</p>
|
418 |
<a href='{target_models[model_id]}'
|
419 |
target='_blank'
|
420 |
style='
|
|
|
442 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
443 |
'>
|
444 |
<h3 style='color: #34495e;'>{model_id}</h3>
|
445 |
+
<p style='color: #7f8c8d;'>Not in top 1000 by downloads</p>
|
446 |
<a href='{target_models[model_id]}'
|
447 |
target='_blank'
|
448 |
style='
|
|
|
465 |
# ์์๊ถ ๋ด ๋ชจ๋ธ
|
466 |
for model in filtered_models:
|
467 |
df_data.append({
|
468 |
+
'Global Rank': model['rank'],
|
469 |
'Model ID': model['id'],
|
470 |
+
'Likes': f"{model.get('likes', 0):,}",
|
471 |
+
'Downloads': f"{model.get('downloads', 0):,}",
|
472 |
'URL': target_models[model['id']]
|
473 |
})
|
474 |
# ์์๊ถ ๋ฐ ๋ชจ๋ธ
|
475 |
for model_id in target_models:
|
476 |
if model_id not in [m['id'] for m in filtered_models]:
|
477 |
df_data.append({
|
478 |
+
'Global Rank': 'Not in top 1000',
|
479 |
'Model ID': model_id,
|
480 |
'Likes': 'N/A',
|
481 |
'Downloads': 'N/A',
|
|
|
874 |
else:
|
875 |
return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ์ํฉ๋๋ค.</div>", pd.DataFrame()
|
876 |
|
|
|
877 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
878 |
gr.Markdown("""
|
879 |
# ๐ค ํ๊น
ํ์ด์ค 'ํ๊ตญ ๋ฆฌ๋๋ณด๋'
|
880 |
์ค์๊ฐ์ผ๋ก Hugging Face์ Spaces์ Models ์ธ๊ธฐ ์์๋ฅผ ๋ถ์ํฉ๋๋ค. ์ ๊ท ๋ฑ๋ก ์์ฒญ: arxivgpt@gmail.com
|
881 |
""")
|
882 |
|
883 |
+
# ์๋ก ๊ณ ์นจ ๋ฒํผ์ ์๋จ์ผ๋ก ์ด๋ํ๊ณ ํ๊ธ๋ก ๋ณ๊ฒฝ
|
884 |
+
refresh_btn = gr.Button("๐ ์๋ก ๊ณ ์นจ", variant="primary")
|
885 |
+
|
886 |
with gr.Tab("Spaces Trending"):
|
887 |
trending_plot = gr.Plot()
|
888 |
trending_info = gr.HTML()
|
|
|
893 |
models_info = gr.HTML()
|
894 |
models_df = gr.DataFrame()
|
895 |
|
|
|
|
|
896 |
def refresh_all_data():
|
897 |
spaces_results = get_spaces_data("trending")
|
898 |
models_results = get_models_data()
|
|
|
913 |
trending_plot.value, trending_info.value, trending_df.value = spaces_results
|
914 |
models_plot.value, models_info.value, models_df.value = models_results
|
915 |
|
916 |
+
|
917 |
# Gradio ์ฑ ์คํ
|
918 |
demo.launch(
|
919 |
server_name="0.0.0.0",
|