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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -47
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
- for sort_params in sort_options:
316
- params = {
317
- 'full': 'true',
318
- 'limit': 1000,
319
- **sort_params
 
 
 
 
 
 
 
 
 
 
 
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 all_found_models:
333
  model_id = normalize_model_id(model.get('id', ''))
334
- if model_id not in seen_ids and model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
335
- seen_ids.add(model_id)
336
  filtered_models.append(model)
337
 
338
- # ๋‹ค์šด๋กœ๋“œ ์ˆ˜๋กœ ์ •๋ ฌ
339
- filtered_models.sort(key=lambda x: x.get('downloads', 0), reverse=True)
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 Trending Rankings (Top 1000)',
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 Trending Rankings</h2>
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', 'N/A'),
474
- 'Downloads': model.get('downloads', 'N/A'),
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",