openfree commited on
Commit
04566a7
Β·
verified Β·
1 Parent(s): c0eced4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -11
app.py CHANGED
@@ -290,14 +290,14 @@ target_models = {
290
 
291
  def get_models_data(progress=gr.Progress()):
292
  """λͺ¨λΈ 데이터 κ°€μ Έμ˜€κΈ°"""
293
- url = "https://huggingface.co/api/models" # κΈ°λ³Έ API μ—”λ“œν¬μΈνŠΈ
294
 
295
  try:
296
  progress(0, desc="Fetching models data...")
297
  params = {
298
  'full': 'true',
299
  'limit': 1000,
300
- 'sort': 'downloads', # λ‹€μš΄λ‘œλ“œ 수둜 μ •λ ¬
301
  'direction': -1
302
  }
303
 
@@ -314,21 +314,33 @@ def get_models_data(progress=gr.Progress()):
314
 
315
  all_models = response.json()
316
  print(f"Total models fetched: {len(all_models)}")
317
-
318
- # λ§€μΉ­ 둜직 μˆ˜μ •
 
 
 
 
 
 
 
 
 
319
  filtered_models = []
320
  for model in all_models:
321
- model_id = model.get('id', '')
322
- if model_id in target_models:
323
- model['rank'] = len(filtered_models) + 1
324
- filtered_models.append(model)
325
- print(f"Found model: {model_id}") # λ””λ²„κΉ…μš©
326
-
327
- print(f"Found {len(filtered_models)} models out of {len(target_models)} target models") # λ””λ²„κΉ…μš©
 
 
328
 
329
  if not filtered_models:
330
  return create_error_plot(), "<div>μ„ νƒλœ λͺ¨λΈμ˜ 데이터λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.</div>", pd.DataFrame()
331
 
 
332
  progress(0.3, desc="Creating visualization...")
333
 
334
  # μ‹œκ°ν™” 생성
@@ -441,9 +453,57 @@ def get_models_data(progress=gr.Progress()):
441
  print(f"Error in get_models_data: {str(e)}")
442
  return create_error_plot(), f"<div>μ—λŸ¬ λ°œμƒ: {str(e)}</div>", pd.DataFrame()
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
 
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
 
448
  # 관심 슀페이슀 URL λ¦¬μŠ€νŠΈμ™€ 정보
449
  target_spaces = {
 
290
 
291
  def get_models_data(progress=gr.Progress()):
292
  """λͺ¨λΈ 데이터 κ°€μ Έμ˜€κΈ°"""
293
+ url = "https://huggingface.co/api/models"
294
 
295
  try:
296
  progress(0, desc="Fetching models data...")
297
  params = {
298
  'full': 'true',
299
  'limit': 1000,
300
+ 'sort': 'downloads',
301
  'direction': -1
302
  }
303
 
 
314
 
315
  all_models = response.json()
316
  print(f"Total models fetched: {len(all_models)}")
317
+
318
+ # API 응닡 확인을 μœ„ν•œ 디버깅
319
+ print("First few model IDs from API:")
320
+ for model in all_models[:5]:
321
+ print(f"API Model ID: {model.get('id', 'No ID')}")
322
+
323
+ print("\nTarget model IDs:")
324
+ for model_id in list(target_models.keys())[:5]:
325
+ print(f"Target Model ID: {model_id}")
326
+
327
+ # λ§€μΉ­ 둜직 μˆ˜μ •
328
  filtered_models = []
329
  for model in all_models:
330
+ model_id = model.get('id', '').strip()
331
+ for target_id in target_models:
332
+ if model_id.lower() == target_id.lower(): # λŒ€μ†Œλ¬Έμž ꡬ뢄 없이 비ꡐ
333
+ model['rank'] = len(filtered_models) + 1
334
+ filtered_models.append(model)
335
+ print(f"Matched model: {model_id}")
336
+ break
337
+
338
+ print(f"\nMatched {len(filtered_models)} models out of {len(target_models)} targets")
339
 
340
  if not filtered_models:
341
  return create_error_plot(), "<div>μ„ νƒλœ λͺ¨λΈμ˜ 데이터λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.</div>", pd.DataFrame()
342
 
343
+
344
  progress(0.3, desc="Creating visualization...")
345
 
346
  # μ‹œκ°ν™” 생성
 
453
  print(f"Error in get_models_data: {str(e)}")
454
  return create_error_plot(), f"<div>μ—λŸ¬ λ°œμƒ: {str(e)}</div>", pd.DataFrame()
455
 
456
+ # API 응닡 ν˜•μ‹μ— 맞게 λͺ¨λΈ ID μˆ˜μ •
457
+ def normalize_model_id(model_id):
458
+ """λͺ¨λΈ IDλ₯Ό μ •κ·œν™”"""
459
+ return model_id.strip().lower()
460
+
461
+ # λ§€μΉ­ 둜직 μˆ˜μ •
462
+ filtered_models = []
463
+ for model in all_models:
464
+ model_id = normalize_model_id(model.get('id', ''))
465
+ target_id = next(
466
+ (tid for tid in target_models.keys()
467
+ if normalize_model_id(tid) == model_id),
468
+ None
469
+ )
470
+
471
+ if target_id:
472
+ model['rank'] = len(filtered_models) + 1
473
+ filtered_models.append(model)
474
+ print(f"Matched model: {model_id} with target: {target_id}")
475
 
476
+ print(f"\nMatched {len(filtered_models)} models out of {len(target_models)} targets")
477
 
478
+ def try_different_sorts():
479
+ """λ‹€μ–‘ν•œ μ •λ ¬ λ°©μ‹μœΌλ‘œ λͺ¨λΈ 검색"""
480
+ sort_options = [
481
+ {'sort': 'downloads', 'direction': -1},
482
+ {'sort': 'lastModified', 'direction': -1},
483
+ {'sort': 'likes', 'direction': -1}
484
+ ]
485
+
486
+ all_found_models = set()
487
+ for sort_params in sort_options:
488
+ params = {
489
+ 'full': 'true',
490
+ 'limit': 1000,
491
+ **sort_params
492
+ }
493
 
494
+ response = requests.get(url, params=params, headers=headers)
495
+ if response.status_code == 200:
496
+ models = response.json()
497
+ for model in models:
498
+ model_id = normalize_model_id(model.get('id', ''))
499
+ if model_id in [normalize_model_id(tid) for tid in target_models.keys()]:
500
+ all_found_models.add(model_id)
501
+
502
+ return all_found_models
503
+
504
+ # 메인 ν•¨μˆ˜μ—μ„œ μ‚¬μš©
505
+ all_found_models = try_different_sorts()
506
+ print(f"\nTotal unique models found across all sorts: {len(all_found_models)}")
507
 
508
  # 관심 슀페이슀 URL λ¦¬μŠ€νŠΈμ™€ 정보
509
  target_spaces = {