openfree commited on
Commit
82d6e2c
ยท
verified ยท
1 Parent(s): 061837d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -31
app.py CHANGED
@@ -297,47 +297,44 @@ def get_models_data(progress=gr.Progress()):
297
  """๋ชจ๋ธ ID๋ฅผ ์ •๊ทœํ™”"""
298
  return model_id.strip().lower()
299
 
300
- # trending ๋Œ€์‹  ์ผ๋ฐ˜ ๋ชจ๋ธ API ์‚ฌ์šฉ
301
  url = "https://huggingface.co/api/models"
302
 
303
  try:
304
  progress(0, desc="Fetching models data...")
305
- params = {
306
- 'full': 'true',
307
- 'limit': 1000,
308
- 'sort': 'lastModified', # ์ตœ์‹  ์ˆ˜์ •์ˆœ์œผ๋กœ ์ •๋ ฌ
309
- 'direction': -1
310
- }
311
 
312
- headers = {'Accept': 'application/json'}
 
 
 
 
 
 
313
 
314
- response = requests.get(url, params=params, headers=headers)
315
- if response.status_code != 200:
316
- print(f"API ์š”์ฒญ ์‹คํŒจ: {response.status_code}")
317
- print(f"Response: {response.text}")
318
- return create_error_plot(), "<div>๋ชจ๋ธ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
 
319
 
320
-
321
-
322
- models = response.json()
 
 
 
323
 
324
- # target_models์™€ ๋งค์นญ
 
325
  filtered_models = []
326
- model_ranks = {}
327
-
328
- # ์ „์ฒด ์ˆœ์œ„ ์ •๋ณด ์ €์žฅ
329
- for idx, model in enumerate(models, 1):
330
  model_id = normalize_model_id(model.get('id', ''))
331
- model_ranks[model_id] = idx
332
-
333
- # target_models ์ค‘ ์ˆœ์œ„๊ถŒ ๋‚ด ๋ชจ๋ธ ํ•„ํ„ฐ๋ง
334
- for model in models:
335
- if normalize_model_id(model.get('id', '')) in [normalize_model_id(tid) for tid in target_models.keys()]:
336
- model['rank'] = model_ranks[normalize_model_id(model.get('id', ''))]
337
  filtered_models.append(model)
338
 
339
- # ์ˆœ์œ„๋กœ ์ •๋ ฌ
340
- filtered_models.sort(key=lambda x: x['rank'])
341
 
342
  # ์ˆœ์œ„ ํ• ๋‹น
343
  for idx, model in enumerate(filtered_models, 1):
@@ -373,7 +370,7 @@ def get_models_data(progress=gr.Progress()):
373
 
374
  fig.update_layout(
375
  title={
376
- 'text': 'Hugging Face Models Trending Rankings (Top 1000)',
377
  'y':0.95,
378
  'x':0.5,
379
  'xanchor': 'center',
@@ -397,7 +394,7 @@ def get_models_data(progress=gr.Progress()):
397
  # HTML ์นด๋“œ ์ƒ์„ฑ
398
  html_content = """
399
  <div style='padding: 20px; background: #f5f5f5;'>
400
- <h2 style='color: #2c3e50;'>Models Trending Rankings</h2>
401
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
402
  """
403
 
 
297
  """๋ชจ๋ธ ID๋ฅผ ์ •๊ทœํ™”"""
298
  return model_id.strip().lower()
299
 
 
300
  url = "https://huggingface.co/api/models"
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):
 
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',
 
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