openfree commited on
Commit
cbed34a
โ€ข
1 Parent(s): ee428fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -303,7 +303,7 @@ def get_models_data(progress=gr.Progress()):
303
  progress(0, desc="Fetching models data...")
304
  params = {
305
  'full': 'true',
306
- 'limit': 1000,
307
  'sort': 'downloads',
308
  'direction': -1
309
  }
@@ -320,21 +320,30 @@ def get_models_data(progress=gr.Progress()):
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'])
@@ -350,11 +359,11 @@ def get_models_data(progress=gr.Progress()):
350
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
351
  ids = [model['id'] for model in filtered_models]
352
  ranks = [model['rank'] for model in filtered_models]
353
- likes = [model.get('likes', 0) for model in filtered_models]
354
- downloads = [model.get('downloads', 0) for model in filtered_models]
355
 
356
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
357
- y_values = [1001 - r for r in ranks]
358
 
359
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
360
  fig.add_trace(go.Bar(
@@ -369,7 +378,7 @@ def get_models_data(progress=gr.Progress()):
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',
@@ -378,9 +387,9 @@ def get_models_data(progress=gr.Progress()):
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)],
383
- range=[0, 1000]
384
  ),
385
  height=800,
386
  showlegend=False,
@@ -393,7 +402,7 @@ def get_models_data(progress=gr.Progress()):
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
 
@@ -401,8 +410,9 @@ def get_models_data(progress=gr.Progress()):
401
  for model in filtered_models:
402
  model_id = model['id']
403
  rank = model['rank']
404
- likes = model.get('likes', 0)
405
- downloads = model.get('downloads', 0)
 
406
 
407
  html_content += f"""
408
  <div style='
@@ -413,6 +423,7 @@ def get_models_data(progress=gr.Progress()):
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]}'
@@ -442,7 +453,7 @@ def get_models_data(progress=gr.Progress()):
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='
@@ -467,16 +478,18 @@ def get_models_data(progress=gr.Progress()):
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',
482
  'URL': target_models[model_id]
 
303
  progress(0, desc="Fetching models data...")
304
  params = {
305
  'full': 'true',
306
+ 'limit': 3000, # 3000๊ฐœ๋กœ ์ฆ๊ฐ€
307
  'sort': 'downloads',
308
  'direction': -1
309
  }
 
320
 
321
  # ์ „์ฒด ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ (๋‹ค์šด๋กœ๋“œ ์ˆ˜ ๊ธฐ์ค€)
322
  model_ranks = {}
323
+ model_data = {} # ๋ชจ๋“  ๋ชจ๋ธ์˜ ์ƒ์„ธ ๋ฐ์ดํ„ฐ ์ €์žฅ
324
+
325
  for idx, model in enumerate(models, 1):
326
  model_id = normalize_model_id(model.get('id', ''))
327
+ model_data[model_id] = {
328
  'rank': idx,
329
  'downloads': model.get('downloads', 0),
330
+ 'likes': model.get('likes', 0),
331
+ 'title': model.get('title', 'No Title')
332
  }
333
 
334
  # target_models ์ค‘ ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ ํ•„ํ„ฐ๋ง
335
  filtered_models = []
336
+ for target_id in target_models.keys():
337
+ normalized_target_id = normalize_model_id(target_id)
338
+ if normalized_target_id in model_data:
339
+ model_info = {
340
+ 'id': target_id,
341
+ 'rank': model_data[normalized_target_id]['rank'],
342
+ 'downloads': model_data[normalized_target_id]['downloads'],
343
+ 'likes': model_data[normalized_target_id]['likes'],
344
+ 'title': model_data[normalized_target_id]['title']
345
+ }
346
+ filtered_models.append(model_info)
347
 
348
  # ์ˆœ์œ„๋กœ ์ •๋ ฌ
349
  filtered_models.sort(key=lambda x: x['rank'])
 
359
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
360
  ids = [model['id'] for model in filtered_models]
361
  ranks = [model['rank'] for model in filtered_models]
362
+ likes = [model['likes'] for model in filtered_models]
363
+ downloads = [model['downloads'] for model in filtered_models]
364
 
365
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
366
+ y_values = [3001 - r for r in ranks] # 3000์œผ๋กœ ๋ณ€๊ฒฝ
367
 
368
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
369
  fig.add_trace(go.Bar(
 
378
 
379
  fig.update_layout(
380
  title={
381
+ 'text': 'Hugging Face Models Global Download Rankings (Top 3000)',
382
  'y':0.95,
383
  'x':0.5,
384
  'xanchor': 'center',
 
387
  xaxis_title='Model ID',
388
  yaxis_title='Global Rank',
389
  yaxis=dict(
390
+ ticktext=[str(i) for i in range(1, 3001, 150)], # ๊ฐ„๊ฒฉ ์กฐ์ •
391
+ tickvals=[3001 - i for i in range(1, 3001, 150)],
392
+ range=[0, 3000]
393
  ),
394
  height=800,
395
  showlegend=False,
 
402
  # HTML ์นด๋“œ ์ƒ์„ฑ
403
  html_content = """
404
  <div style='padding: 20px; background: #f5f5f5;'>
405
+ <h2 style='color: #2c3e50;'>Models Global Download Rankings (Top 3000)</h2>
406
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
407
  """
408
 
 
410
  for model in filtered_models:
411
  model_id = model['id']
412
  rank = model['rank']
413
+ likes = model['likes']
414
+ downloads = model['downloads']
415
+ title = model.get('title', 'No Title')
416
 
417
  html_content += f"""
418
  <div style='
 
423
  transition: transform 0.2s;
424
  '>
425
  <h3 style='color: #34495e;'>Global Rank #{rank} - {model_id}</h3>
426
+ <p style='color: #2c3e50;'>{title}</p>
427
  <p style='color: #7f8c8d;'>๐Ÿ‘ Likes: {likes:,}</p>
428
  <p style='color: #7f8c8d;'>โฌ‡๏ธ Downloads: {downloads:,}</p>
429
  <a href='{target_models[model_id]}'
 
453
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
454
  '>
455
  <h3 style='color: #34495e;'>{model_id}</h3>
456
+ <p style='color: #7f8c8d;'>Not in top 3000 by downloads</p>
457
  <a href='{target_models[model_id]}'
458
  target='_blank'
459
  style='
 
478
  df_data.append({
479
  'Global Rank': model['rank'],
480
  'Model ID': model['id'],
481
+ 'Title': model.get('title', 'No Title'),
482
+ 'Likes': f"{model['likes']:,}",
483
+ 'Downloads': f"{model['downloads']:,}",
484
  'URL': target_models[model['id']]
485
  })
486
  # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ
487
  for model_id in target_models:
488
  if model_id not in [m['id'] for m in filtered_models]:
489
  df_data.append({
490
+ 'Global Rank': 'Not in top 3000',
491
  'Model ID': model_id,
492
+ 'Title': 'N/A',
493
  'Likes': 'N/A',
494
  'Downloads': 'N/A',
495
  'URL': target_models[model_id]