openfree commited on
Commit
0a5f955
ยท
verified ยท
1 Parent(s): 5f52c69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -52
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
- all_global_models = []
306
- page_size = 10000
307
- max_models = 50000 # ์ถฉ๋ถ„ํžˆ ํฐ ์ˆ˜๋กœ ์„ค์ •
308
-
309
- for offset in range(0, max_models, page_size):
310
- global_params = {
311
- 'full': 'true',
312
- 'limit': page_size,
313
- 'offset': offset,
314
- 'sort': 'downloads',
315
- 'direction': -1
316
- }
317
-
318
- global_response = requests.get(
319
- "https://huggingface.co/api/models",
320
- headers={'Accept': 'application/json'},
321
- params=global_params
322
- )
323
 
324
- if global_response.status_code != 200:
325
- print(f"Failed to fetch global rankings page {offset//page_size + 1}")
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
- print(f"Total models fetched: {len(global_ranks)}")
346
-
347
- # target_models์˜ ์ˆœ์œ„ ํ™•์ธ ๋ฐ ์ €์žฅ
348
  filtered_models = []
349
  for model_id in target_models.keys():
350
- normalized_id = normalize_model_id(model_id)
351
- if normalized_id in global_ranks:
352
- rank_info = global_ranks[normalized_id]
353
- model_info = {
354
- 'id': model_id,
355
- 'global_rank': rank_info['rank'],
356
- 'downloads': rank_info['downloads'],
357
- 'likes': rank_info['likes'],
358
- 'title': 'No Title' # ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๊ฐœ๋ณ„ API ํ˜ธ์ถœ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Œ
359
- }
360
- print(f"Found {model_id} at rank {rank_info['rank']}")
361
- else:
362
- model_info = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  'id': model_id,
364
- 'global_rank': 'Not found',
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