openfree commited on
Commit
b50e7a2
·
verified ·
1 Parent(s): 1fed40f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -54
app.py CHANGED
@@ -319,28 +319,34 @@ def get_korea_models():
319
  print(f"Error fetching Korea models: {str(e)}")
320
  return []
321
 
322
- def get_all_models(limit=1000):
323
  """모든 모델과 Korea 관련 모델 가져오기"""
324
  all_models = []
 
325
 
326
- # 1. 일반 모델 리스트 가져오기
327
- params = {
328
- "limit": limit,
329
- "full": "True",
330
- "config": "True"
331
- }
332
-
333
- response = requests.get(
334
- "https://huggingface.co/api/models",
335
- headers={'Accept': 'application/json'},
336
- params=params
337
- )
338
-
339
- if response.status_code == 200:
340
- all_models.extend(response.json())
341
- print(f"Fetched {len(all_models)} general models")
 
 
 
 
 
342
 
343
- # 2. Korea 검색 결과 가져오기
344
  korea_params = {
345
  "search": "korea",
346
  "full": "True",
@@ -365,30 +371,6 @@ def get_all_models(limit=1000):
365
  all_models.append(model)
366
  existing_ids.add(model.get('id', ''))
367
 
368
- # 3. Korean 검색 결과 가져오기
369
- korean_params = {
370
- "search": "korean",
371
- "full": "True",
372
- "config": "True",
373
- "limit": limit
374
- }
375
-
376
- korean_response = requests.get(
377
- "https://huggingface.co/api/models",
378
- headers={'Accept': 'application/json'},
379
- params=korean_params
380
- )
381
-
382
- if korean_response.status_code == 200:
383
- korean_models = korean_response.json()
384
- print(f"Fetched {len(korean_models)} Korean-related models")
385
-
386
- # 중복 제거하면서 Korean 모델 추가
387
- for model in korean_models:
388
- if model.get('id', '') not in existing_ids:
389
- all_models.append(model)
390
- existing_ids.add(model.get('id', ''))
391
-
392
  print(f"Total unique models: {len(all_models)}")
393
  return all_models[:limit]
394
 
@@ -407,8 +389,8 @@ def get_models_data(progress=gr.Progress()):
407
  empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
408
  return fig, error_html, empty_df
409
 
410
- # 일반 모델과 Korea 관련 모델 모두 가져오기
411
- all_global_models = get_all_models(limit=1000)
412
  korea_models = get_korea_models()
413
 
414
  # 모든 모델 통합 (중복 제거)
@@ -439,7 +421,7 @@ def get_models_data(progress=gr.Progress()):
439
  filtered_models.append({
440
  'id': model_id,
441
  'global_rank': next((idx for idx, m in enumerate(all_models, 1)
442
- if m.get('id', '').strip() == model_id.strip()), 'Not in top 1000'),
443
  'downloads': model_data.get('downloads', 0),
444
  'likes': model_data.get('likes', 0),
445
  'title': model_data.get('title', 'No Title'),
@@ -448,7 +430,7 @@ def get_models_data(progress=gr.Progress()):
448
  else:
449
  filtered_models.append({
450
  'id': model_id,
451
- 'global_rank': 'Not in top 1000',
452
  'downloads': 0,
453
  'likes': 0,
454
  'title': 'No Title',
@@ -470,7 +452,7 @@ def get_models_data(progress=gr.Progress()):
470
 
471
  fig.add_trace(go.Bar(
472
  x=ids,
473
- y=[1001 - r for r in ranks], # Y축 반전
474
  text=[f"Rank: #{r}<br>Downloads: {format(m['downloads'], ',')}<br>Likes: {format(m['likes'], ',')}"
475
  for r, m in zip(ranks, valid_models)],
476
  textposition='auto',
@@ -480,27 +462,29 @@ def get_models_data(progress=gr.Progress()):
480
  ))
481
 
482
  fig.update_layout(
483
- title="HuggingFace Models Global Rankings",
484
  xaxis_title="Model ID",
485
  yaxis_title="Global Rank",
486
  yaxis=dict(
487
- ticktext=[f"#{i}" for i in range(1, 1001, 50)],
488
- tickvals=[1001 - i for i in range(1, 1001, 50)],
489
- range=[0, 1000]
490
  ),
491
  height=800,
492
- showlegend=False
 
 
493
  )
494
 
495
  # HTML 카드 생성
496
  html_content = """
497
  <div style='padding: 20px; background: #f5f5f5;'>
498
- <h2 style='color: #2c3e50;'>Models Rankings</h2>
499
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
500
  """
501
 
502
  for model in filtered_models:
503
- rank_display = f"Global Rank #{model['global_rank']}" if isinstance(model['global_rank'], (int, float)) else "Not in top 1000"
504
  korea_badge = "🇰🇷 Korea Search Result" if model['is_korea'] else ""
505
 
506
  html_content += f"""
 
319
  print(f"Error fetching Korea models: {str(e)}")
320
  return []
321
 
322
+ def get_all_models(limit=3000):
323
  """모든 모델과 Korea 관련 모델 가져오기"""
324
  all_models = []
325
+ page_size = 1000 # API의 한 번 요청당 최대 크기
326
 
327
+ # 여러 페이지에 걸쳐 데이터 수집
328
+ for offset in range(0, limit, page_size):
329
+ params = {
330
+ 'limit': min(page_size, limit - offset),
331
+ 'full': 'True',
332
+ 'config': 'True',
333
+ 'offset': offset
334
+ }
335
+
336
+ response = requests.get(
337
+ "https://huggingface.co/api/models",
338
+ headers={'Accept': 'application/json'},
339
+ params=params
340
+ )
341
+
342
+ if response.status_code == 200:
343
+ all_models.extend(response.json())
344
+ print(f"Fetched models {offset+1} to {offset+len(response.json())}")
345
+ else:
346
+ print(f"Failed to fetch models at offset {offset}: {response.status_code}")
347
+ break
348
 
349
+ # Korea 검색 결과도 동일하게 확장
350
  korea_params = {
351
  "search": "korea",
352
  "full": "True",
 
371
  all_models.append(model)
372
  existing_ids.add(model.get('id', ''))
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  print(f"Total unique models: {len(all_models)}")
375
  return all_models[:limit]
376
 
 
389
  empty_df = pd.DataFrame(columns=['Global Rank', 'Model ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
390
  return fig, error_html, empty_df
391
 
392
+ # 일반 모델과 Korea 관련 모델 모두 가져오기 (3000위까지)
393
+ all_global_models = get_all_models(limit=3000)
394
  korea_models = get_korea_models()
395
 
396
  # 모든 모델 통합 (중복 제거)
 
421
  filtered_models.append({
422
  'id': model_id,
423
  'global_rank': next((idx for idx, m in enumerate(all_models, 1)
424
+ if m.get('id', '').strip() == model_id.strip()), 'Not in top 3000'),
425
  'downloads': model_data.get('downloads', 0),
426
  'likes': model_data.get('likes', 0),
427
  'title': model_data.get('title', 'No Title'),
 
430
  else:
431
  filtered_models.append({
432
  'id': model_id,
433
+ 'global_rank': 'Not in top 3000',
434
  'downloads': 0,
435
  'likes': 0,
436
  'title': 'No Title',
 
452
 
453
  fig.add_trace(go.Bar(
454
  x=ids,
455
+ y=[3001 - r for r in ranks], # Y축 범위 3000까지 확장
456
  text=[f"Rank: #{r}<br>Downloads: {format(m['downloads'], ',')}<br>Likes: {format(m['likes'], ',')}"
457
  for r, m in zip(ranks, valid_models)],
458
  textposition='auto',
 
462
  ))
463
 
464
  fig.update_layout(
465
+ title="HuggingFace Models Global Rankings (Up to #3000)",
466
  xaxis_title="Model ID",
467
  yaxis_title="Global Rank",
468
  yaxis=dict(
469
+ ticktext=[f"#{i}" for i in range(1, 3001, 100)],
470
+ tickvals=[3001 - i for i in range(1, 3001, 100)],
471
+ range=[0, 3000]
472
  ),
473
  height=800,
474
+ showlegend=False,
475
+ template='plotly_white',
476
+ xaxis_tickangle=-45
477
  )
478
 
479
  # HTML 카드 생성
480
  html_content = """
481
  <div style='padding: 20px; background: #f5f5f5;'>
482
+ <h2 style='color: #2c3e50;'>Models Rankings (Up to #3000)</h2>
483
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
484
  """
485
 
486
  for model in filtered_models:
487
+ rank_display = f"Global Rank #{model['global_rank']}" if isinstance(model['global_rank'], (int, float)) else "Not in top 3000"
488
  korea_badge = "🇰🇷 Korea Search Result" if model['is_korea'] else ""
489
 
490
  html_content += f"""