openfree commited on
Commit
59bbced
ยท
verified ยท
1 Parent(s): 82d6e2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -301,44 +301,43 @@ def get_models_data(progress=gr.Progress()):
301
 
302
  try:
303
  progress(0, desc="Fetching models data...")
 
 
 
 
 
 
304
 
305
- # ์—ฌ๋Ÿฌ ์ •๋ ฌ ๋ฐฉ์‹์œผ๋กœ ์‹œ๋„
306
- all_found_models = []
307
- sort_options = [
308
- {'sort': 'downloads', 'direction': -1},
309
- {'sort': 'lastModified', 'direction': -1},
310
- {'sort': 'likes', 'direction': -1}
311
- ]
312
 
313
- for sort_params in sort_options:
314
- params = {
315
- 'full': 'true',
316
- 'limit': 1000,
317
- **sort_params
 
 
 
 
 
 
 
 
 
 
 
318
  }
319
-
320
- headers = {'Accept': 'application/json'}
321
-
322
- response = requests.get(url, params=params, headers=headers)
323
- if response.status_code == 200:
324
- models = response.json()
325
- all_found_models.extend(models)
326
 
327
- # ์ค‘๋ณต ์ œ๊ฑฐ
328
- seen_ids = set()
329
  filtered_models = []
330
- for model in all_found_models:
331
  model_id = normalize_model_id(model.get('id', ''))
332
- if model_id not in seen_ids and model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
333
- seen_ids.add(model_id)
334
  filtered_models.append(model)
335
 
336
- # ๋‹ค์šด๋กœ๋“œ ์ˆ˜์™€ ์ข‹์•„์š” ์ˆ˜๋กœ ์ •๋ ฌ
337
- filtered_models.sort(key=lambda x: (x.get('downloads', 0), x.get('likes', 0)), reverse=True)
338
-
339
- # ์ˆœ์œ„ ํ• ๋‹น
340
- for idx, model in enumerate(filtered_models, 1):
341
- model['rank'] = idx
342
 
343
  if not filtered_models:
344
  return create_error_plot(), "<div>์„ ํƒ๋œ ๋ชจ๋ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
@@ -361,7 +360,7 @@ def get_models_data(progress=gr.Progress()):
361
  fig.add_trace(go.Bar(
362
  x=ids,
363
  y=y_values,
364
- text=[f"Rank: {r}<br>Likes: {l}<br>Downloads: {d}"
365
  for r, l, d in zip(ranks, likes, downloads)],
366
  textposition='auto',
367
  marker_color='rgb(158,202,225)',
@@ -370,14 +369,14 @@ def get_models_data(progress=gr.Progress()):
370
 
371
  fig.update_layout(
372
  title={
373
- 'text': 'Hugging Face Models Rankings by Downloads (Top 1000)',
374
  'y':0.95,
375
  'x':0.5,
376
  'xanchor': 'center',
377
  'yanchor': 'top'
378
  },
379
  xaxis_title='Model ID',
380
- yaxis_title='Rank',
381
  yaxis=dict(
382
  ticktext=[str(i) for i in range(1, 1001, 50)],
383
  tickvals=[1001 - i for i in range(1, 1001, 50)],
@@ -394,7 +393,7 @@ def get_models_data(progress=gr.Progress()):
394
  # HTML ์นด๋“œ ์ƒ์„ฑ
395
  html_content = """
396
  <div style='padding: 20px; background: #f5f5f5;'>
397
- <h2 style='color: #2c3e50;'>Models Rankings by Downloads</h2>
398
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
399
  """
400
 
@@ -413,9 +412,9 @@ def get_models_data(progress=gr.Progress()):
413
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
414
  transition: transform 0.2s;
415
  '>
416
- <h3 style='color: #34495e;'>Rank #{rank} - {model_id}</h3>
417
- <p style='color: #7f8c8d;'>๐Ÿ‘ Likes: {likes}</p>
418
- <p style='color: #7f8c8d;'>โฌ‡๏ธ Downloads: {downloads}</p>
419
  <a href='{target_models[model_id]}'
420
  target='_blank'
421
  style='
@@ -443,7 +442,7 @@ def get_models_data(progress=gr.Progress()):
443
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
444
  '>
445
  <h3 style='color: #34495e;'>{model_id}</h3>
446
- <p style='color: #7f8c8d;'>Not in top 1000</p>
447
  <a href='{target_models[model_id]}'
448
  target='_blank'
449
  style='
@@ -466,17 +465,17 @@ def get_models_data(progress=gr.Progress()):
466
  # ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ
467
  for model in filtered_models:
468
  df_data.append({
469
- 'Rank': model['rank'],
470
  'Model ID': model['id'],
471
- 'Likes': model.get('likes', 'N/A'),
472
- 'Downloads': model.get('downloads', 'N/A'),
473
  'URL': target_models[model['id']]
474
  })
475
  # ์ˆœ์œ„๊ถŒ ๋ฐ– ๋ชจ๋ธ
476
  for model_id in target_models:
477
  if model_id not in [m['id'] for m in filtered_models]:
478
  df_data.append({
479
- 'Rank': 'Not in top 1000',
480
  'Model ID': model_id,
481
  'Likes': 'N/A',
482
  'Downloads': 'N/A',
@@ -875,13 +874,15 @@ def refresh_data():
875
  else:
876
  return create_error_plot(), "<div>API ์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.</div>", pd.DataFrame()
877
 
878
-
879
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
880
  gr.Markdown("""
881
  # ๐Ÿค— ํ—ˆ๊น…ํŽ˜์ด์Šค 'ํ•œ๊ตญ ๋ฆฌ๋”๋ณด๋“œ'
882
  ์‹ค์‹œ๊ฐ„์œผ๋กœ Hugging Face์˜ Spaces์™€ Models ์ธ๊ธฐ ์ˆœ์œ„๋ฅผ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. ์‹ ๊ทœ ๋“ฑ๋ก ์š”์ฒญ: [email protected]
883
  """)
884
 
 
 
 
885
  with gr.Tab("Spaces Trending"):
886
  trending_plot = gr.Plot()
887
  trending_info = gr.HTML()
@@ -892,8 +893,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
892
  models_info = gr.HTML()
893
  models_df = gr.DataFrame()
894
 
895
- refresh_btn = gr.Button("๐Ÿ”„ Refresh Data", variant="primary")
896
-
897
  def refresh_all_data():
898
  spaces_results = get_spaces_data("trending")
899
  models_results = get_models_data()
@@ -914,6 +913,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
914
  trending_plot.value, trending_info.value, trending_df.value = spaces_results
915
  models_plot.value, models_info.value, models_df.value = models_results
916
 
 
917
  # Gradio ์•ฑ ์‹คํ–‰
918
  demo.launch(
919
  server_name="0.0.0.0",
 
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 ์ธ๊ธฐ ์ˆœ์œ„๋ฅผ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. ์‹ ๊ทœ ๋“ฑ๋ก ์š”์ฒญ: [email protected]
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",