Update app.py
Browse files
app.py
CHANGED
@@ -301,36 +301,26 @@ def get_models_data(progress=gr.Progress()):
|
|
301 |
try:
|
302 |
progress(0, desc="Fetching global rankings...")
|
303 |
|
304 |
-
# ์ ์ฒด ๋ชจ๋ธ
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
params=global_params
|
322 |
-
)
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
continue
|
327 |
-
|
328 |
-
page_models = global_response.json()
|
329 |
-
if not page_models: # ๋ ์ด์ ๋ชจ๋ธ์ด ์์ผ๋ฉด ์ค๋จ
|
330 |
-
break
|
331 |
-
|
332 |
-
all_global_models.extend(page_models)
|
333 |
-
print(f"Fetched {len(all_global_models)} models so far...")
|
334 |
|
335 |
# ์ ์ฒด ์์ ๋งต ์์ฑ
|
336 |
global_ranks = {}
|
@@ -339,35 +329,51 @@ def get_models_data(progress=gr.Progress()):
|
|
339 |
global_ranks[model_id] = {
|
340 |
'rank': idx,
|
341 |
'downloads': model.get('downloads', 0),
|
342 |
-
'likes': model.get('likes', 0)
|
|
|
343 |
}
|
344 |
|
345 |
-
|
346 |
-
|
347 |
-
# target_models์ ์์ ํ์ธ ๋ฐ ์ ์ฅ
|
348 |
filtered_models = []
|
349 |
for model_id in target_models.keys():
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
'id': model_id,
|
364 |
-
'global_rank': 'Not
|
365 |
'downloads': 0,
|
366 |
'likes': 0,
|
367 |
'title': 'No Title'
|
368 |
-
}
|
369 |
-
print(f"Model {model_id} not found in rankings")
|
370 |
-
filtered_models.append(model_info)
|
371 |
|
372 |
# ์์๋ก ์ ๋ ฌ
|
373 |
filtered_models.sort(key=lambda x: float('inf') if isinstance(x['global_rank'], str) else x['global_rank'])
|
@@ -408,7 +414,7 @@ def get_models_data(progress=gr.Progress()):
|
|
408 |
|
409 |
fig.update_layout(
|
410 |
title={
|
411 |
-
'text': 'Hugging Face Models Global Rankings',
|
412 |
'y':0.95,
|
413 |
'x':0.5,
|
414 |
'xanchor': 'center',
|
@@ -428,7 +434,7 @@ def get_models_data(progress=gr.Progress()):
|
|
428 |
# HTML ์นด๋ ์์ฑ
|
429 |
html_content = """
|
430 |
<div style='padding: 20px; background: #f5f5f5;'>
|
431 |
-
<h2 style='color: #2c3e50;'>Models Global Rankings</h2>
|
432 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
433 |
"""
|
434 |
|
|
|
301 |
try:
|
302 |
progress(0, desc="Fetching global rankings...")
|
303 |
|
304 |
+
# ์ ์ฒด ๋ชจ๋ธ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ (์ข์์ ์์ผ๋ก ์ ๋ ฌ)
|
305 |
+
global_params = {
|
306 |
+
'full': 'true',
|
307 |
+
'limit': 3000,
|
308 |
+
'sort': 'likes', # ์ข์์ ์์ผ๋ก ๋ณ๊ฒฝ
|
309 |
+
'direction': -1
|
310 |
+
}
|
311 |
+
|
312 |
+
global_response = requests.get(
|
313 |
+
"https://huggingface.co/api/models",
|
314 |
+
headers={'Accept': 'application/json'},
|
315 |
+
params=global_params
|
316 |
+
)
|
317 |
+
|
318 |
+
if global_response.status_code != 200:
|
319 |
+
print(f"Failed to fetch global rankings: {global_response.status_code}")
|
320 |
+
return create_error_plot(), "<div>์ ์ฒด ์์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์คํจํ์ต๋๋ค.</div>", pd.DataFrame()
|
|
|
|
|
321 |
|
322 |
+
all_global_models = global_response.json()
|
323 |
+
print(f"Fetched {len(all_global_models)} models")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
# ์ ์ฒด ์์ ๋งต ์์ฑ
|
326 |
global_ranks = {}
|
|
|
329 |
global_ranks[model_id] = {
|
330 |
'rank': idx,
|
331 |
'downloads': model.get('downloads', 0),
|
332 |
+
'likes': model.get('likes', 0),
|
333 |
+
'title': model.get('title', 'No Title')
|
334 |
}
|
335 |
|
336 |
+
# target_models์ ์์ธ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
|
|
|
|
337 |
filtered_models = []
|
338 |
for model_id in target_models.keys():
|
339 |
+
try:
|
340 |
+
# ๊ฐ๋ณ ๋ชจ๋ธ API ํธ์ถ๋ก ์ ํํ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
341 |
+
model_url_api = f"https://huggingface.co/api/models/{model_id}"
|
342 |
+
response = requests.get(model_url_api, headers={'Accept': 'application/json'})
|
343 |
+
|
344 |
+
if response.status_code == 200:
|
345 |
+
model_data = response.json()
|
346 |
+
normalized_id = normalize_model_id(model_id)
|
347 |
+
|
348 |
+
# ์ ์ฒด ์์ ์ ๋ณด์ ๊ฐ๋ณ ๋ชจ๋ธ ์ ๋ณด ๊ฒฐํฉ
|
349 |
+
rank_info = global_ranks.get(normalized_id, {})
|
350 |
+
model_info = {
|
351 |
+
'id': model_id,
|
352 |
+
'global_rank': rank_info.get('rank', 'Not in top 3000'),
|
353 |
+
'downloads': model_data.get('downloads', 0),
|
354 |
+
'likes': model_data.get('likes', 0),
|
355 |
+
'title': model_data.get('title', 'No Title')
|
356 |
+
}
|
357 |
+
filtered_models.append(model_info)
|
358 |
+
print(f"Model {model_id}: Rank={model_info['global_rank']}, Likes={model_info['likes']}, Downloads={model_info['downloads']}")
|
359 |
+
else:
|
360 |
+
print(f"Failed to fetch data for {model_id}: {response.status_code}")
|
361 |
+
filtered_models.append({
|
362 |
+
'id': model_id,
|
363 |
+
'global_rank': 'Not in top 3000',
|
364 |
+
'downloads': 0,
|
365 |
+
'likes': 0,
|
366 |
+
'title': 'No Title'
|
367 |
+
})
|
368 |
+
except Exception as e:
|
369 |
+
print(f"Error fetching data for {model_id}: {str(e)}")
|
370 |
+
filtered_models.append({
|
371 |
'id': model_id,
|
372 |
+
'global_rank': 'Not in top 3000',
|
373 |
'downloads': 0,
|
374 |
'likes': 0,
|
375 |
'title': 'No Title'
|
376 |
+
})
|
|
|
|
|
377 |
|
378 |
# ์์๋ก ์ ๋ ฌ
|
379 |
filtered_models.sort(key=lambda x: float('inf') if isinstance(x['global_rank'], str) else x['global_rank'])
|
|
|
414 |
|
415 |
fig.update_layout(
|
416 |
title={
|
417 |
+
'text': 'Hugging Face Models Global Rankings (by Likes)',
|
418 |
'y':0.95,
|
419 |
'x':0.5,
|
420 |
'xanchor': 'center',
|
|
|
434 |
# HTML ์นด๋ ์์ฑ
|
435 |
html_content = """
|
436 |
<div style='padding: 20px; background: #f5f5f5;'>
|
437 |
+
<h2 style='color: #2c3e50;'>Models Global Rankings (by Likes)</h2>
|
438 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
439 |
"""
|
440 |
|