openfree commited on
Commit
4c93d45
ยท
verified ยท
1 Parent(s): 8ef1d19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -66
app.py CHANGED
@@ -295,7 +295,11 @@ target_models = {
295
 
296
  def get_models_data(progress=gr.Progress()):
297
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
298
- url = "https://huggingface.co/api/models" # ๊ธฐ๋ณธ ๋ชจ๋ธ API ์—”๋“œํฌ์ธํŠธ
 
 
 
 
299
 
300
  try:
301
  progress(0, desc="Fetching models data...")
@@ -324,38 +328,36 @@ def get_models_data(progress=gr.Progress()):
324
 
325
  # ์ค‘๋ณต ์ œ๊ฑฐ
326
  seen_ids = set()
327
- unique_models = []
328
  for model in all_found_models:
329
- model_id = model.get('id', '')
330
- if model_id not in seen_ids and model_id in target_models:
331
  seen_ids.add(model_id)
332
- unique_models.append(model)
333
 
334
  # ๋‹ค์šด๋กœ๋“œ ์ˆ˜๋กœ ์ •๋ ฌ
335
- unique_models.sort(key=lambda x: x.get('downloads', 0), reverse=True)
336
 
337
  # ์ˆœ์œ„ ํ• ๋‹น
338
- for idx, model in enumerate(unique_models, 1):
339
  model['rank'] = idx
340
 
341
- if not unique_models:
342
  return create_error_plot(), "<div>์„ ํƒ๋œ ๋ชจ๋ธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</div>", pd.DataFrame()
343
 
344
- # ๋‚˜๋จธ์ง€ ์‹œ๊ฐํ™” ์ฝ”๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ์œ ์ง€
345
  progress(0.3, desc="Creating visualization...")
346
 
347
  # ์‹œ๊ฐํ™” ์ƒ์„ฑ
348
  fig = go.Figure()
349
 
350
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
351
- ids = [model['id'] for model in unique_models]
352
- ranks = [model['rank'] for model in unique_models]
353
- likes = [model.get('likes', 0) for model in unique_models]
354
- downloads = [model.get('downloads', 0) for model in unique_models]
355
 
356
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
357
  y_values = [1001 - r for r in ranks]
358
-
359
 
360
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
361
  fig.add_trace(go.Bar(
@@ -492,60 +494,10 @@ def get_models_data(progress=gr.Progress()):
492
  print(f"Error in get_models_data: {str(e)}")
493
  return create_error_plot(), f"<div>์—๋Ÿฌ ๋ฐœ์ƒ: {str(e)}</div>", pd.DataFrame()
494
 
495
- # API ์‘๋‹ต ํ˜•์‹์— ๋งž๊ฒŒ ๋ชจ๋ธ ID ์ˆ˜์ •
496
- def normalize_model_id(model_id):
497
- """๋ชจ๋ธ ID๋ฅผ ์ •๊ทœํ™”"""
498
- return model_id.strip().lower()
499
-
500
- # ๋งค์นญ ๋กœ์ง ์ˆ˜์ •
501
- filtered_models = []
502
- for model in all_models:
503
- model_id = normalize_model_id(model.get('id', ''))
504
- target_id = next(
505
- (tid for tid in target_models.keys()
506
- if normalize_model_id(tid) == model_id),
507
- None
508
- )
509
-
510
- if target_id:
511
- model['rank'] = len(filtered_models) + 1
512
- filtered_models.append(model)
513
- print(f"Matched model: {model_id} with target: {target_id}")
514
-
515
- print(f"\nMatched {len(filtered_models)} models out of {len(target_models)} targets")
516
-
517
- def try_different_sorts():
518
- """๋‹ค์–‘ํ•œ ์ •๋ ฌ ๋ฐฉ์‹์œผ๋กœ ๋ชจ๋ธ ๊ฒ€์ƒ‰"""
519
- sort_options = [
520
- {'sort': 'downloads', 'direction': -1},
521
- {'sort': 'lastModified', 'direction': -1},
522
- {'sort': 'likes', 'direction': -1}
523
- ]
524
-
525
- all_found_models = set()
526
- for sort_params in sort_options:
527
- params = {
528
- 'full': 'true',
529
- 'limit': 1000,
530
- **sort_params
531
- }
532
-
533
- response = requests.get(url, params=params, headers=headers)
534
- if response.status_code == 200:
535
- models = response.json()
536
- for model in models:
537
- model_id = normalize_model_id(model.get('id', ''))
538
- if model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
539
- all_found_models.add(model_id)
540
-
541
- return all_found_models
542
-
543
- # ๋ฉ”์ธ ํ•จ์ˆ˜์—์„œ ์‚ฌ์šฉ
544
- all_found_models = try_different_sorts()
545
- print(f"\nTotal unique models found across all sorts: {len(all_found_models)}")
546
-
547
  # ๊ด€์‹ฌ ์ŠคํŽ˜์ด์Šค URL ๋ฆฌ์ŠคํŠธ์™€ ์ •๋ณด
548
  target_spaces = {
 
 
549
  "ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
550
  "ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
551
  "fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
 
295
 
296
  def get_models_data(progress=gr.Progress()):
297
  """๋ชจ๋ธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ"""
298
+ def normalize_model_id(model_id):
299
+ """๋ชจ๋ธ ID๋ฅผ ์ •๊ทœํ™”"""
300
+ return model_id.strip().lower()
301
+
302
+ url = "https://huggingface.co/api/models"
303
 
304
  try:
305
  progress(0, desc="Fetching models data...")
 
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()
347
 
 
348
  progress(0.3, desc="Creating visualization...")
349
 
350
  # ์‹œ๊ฐํ™” ์ƒ์„ฑ
351
  fig = go.Figure()
352
 
353
  # ๋ฐ์ดํ„ฐ ์ค€๋น„
354
+ ids = [model['id'] for model in filtered_models]
355
+ ranks = [model['rank'] for model in filtered_models]
356
+ likes = [model.get('likes', 0) for model in filtered_models]
357
+ downloads = [model.get('downloads', 0) for model in filtered_models]
358
 
359
  # Y์ถ• ๊ฐ’์„ ๋ฐ˜์ „
360
  y_values = [1001 - r for r in ranks]
 
361
 
362
  # ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
363
  fig.add_trace(go.Bar(
 
494
  print(f"Error in get_models_data: {str(e)}")
495
  return create_error_plot(), f"<div>์—๋Ÿฌ ๋ฐœ์ƒ: {str(e)}</div>", pd.DataFrame()
496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  # ๊ด€์‹ฌ ์ŠคํŽ˜์ด์Šค URL ๋ฆฌ์ŠคํŠธ์™€ ์ •๋ณด
498
  target_spaces = {
499
+
500
+ "openfree/Korean-Leaderboard": "https://huggingface.co/spaces/openfree/Korean-Leaderboard",
501
  "ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
502
  "ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
503
  "fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",