openfree commited on
Commit
01538a1
·
verified ·
1 Parent(s): 04566a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -294,53 +294,54 @@ def get_models_data(progress=gr.Progress()):
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
 
304
  headers = {
305
  'Accept': 'application/json',
306
  'User-Agent': 'Mozilla/5.0'
307
  }
308
 
309
- response = requests.get(url, params=params, headers=headers)
310
- if response.status_code != 200:
311
- print(f"API 요청 실패: {response.status_code}")
312
- print(f"Response: {response.text}")
 
 
 
 
 
 
 
 
 
 
 
313
  return create_error_plot(), "<div>모델 데이터를 가져오는데 실패했습니다.</div>", pd.DataFrame()
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
  # 시각화 생성
@@ -351,7 +352,7 @@ def get_models_data(progress=gr.Progress()):
351
  downloads = [model.get('downloads', 0) for model in filtered_models]
352
  likes = [model.get('likes', 0) for model in filtered_models]
353
 
354
- # 다운로드 수를 기준으로 순위 계산
355
  sorted_models = sorted(filtered_models, key=lambda x: x.get('downloads', 0), reverse=True)
356
  for idx, model in enumerate(sorted_models):
357
  model['rank'] = idx + 1
@@ -403,8 +404,8 @@ def get_models_data(progress=gr.Progress()):
403
  """
404
 
405
  for model in sorted_models:
406
- model_id = model.get('id', '')
407
- rank = model.get('rank', 'N/A')
408
  downloads = model.get('downloads', 0)
409
  likes = model.get('likes', 0)
410
 
@@ -439,11 +440,11 @@ def get_models_data(progress=gr.Progress()):
439
 
440
  # 데이터프레임 생성
441
  df = pd.DataFrame([{
442
- 'Rank': model.get('rank', 'N/A'),
443
- 'Model ID': model.get('id', ''),
444
  'Downloads': model.get('downloads', 'N/A'),
445
  'Likes': model.get('likes', 'N/A'),
446
- 'URL': target_models[model.get('id', '')]
447
  } for model in sorted_models])
448
 
449
  progress(1.0, desc="Complete!")
 
294
 
295
  try:
296
  progress(0, desc="Fetching models data...")
297
+
298
+ # 여러 정렬 방식으로 모델 검색
299
+ all_found_models = []
300
+ sort_options = [
301
+ {'sort': 'downloads', 'direction': -1},
302
+ {'sort': 'lastModified', 'direction': -1},
303
+ {'sort': 'likes', 'direction': -1}
304
+ ]
305
 
306
  headers = {
307
  'Accept': 'application/json',
308
  'User-Agent': 'Mozilla/5.0'
309
  }
310
 
311
+ for sort_params in sort_options:
312
+ params = {
313
+ 'full': 'true',
314
+ 'limit': 1000,
315
+ **sort_params
316
+ }
317
+
318
+ response = requests.get(url, params=params, headers=headers)
319
+ if response.status_code == 200:
320
+ models = response.json()
321
+ all_found_models.extend(models)
322
+ print(f"Found {len(models)} models with {sort_params['sort']} sort")
323
+
324
+ if not all_found_models:
325
+ print("No models found from API")
326
  return create_error_plot(), "<div>모델 데이터를 가져오는데 실패했습니다.</div>", pd.DataFrame()
327
 
328
+ # 중복 제거
329
+ unique_models = {model['id']: model for model in all_found_models}.values()
330
+ print(f"Total unique models: {len(unique_models)}")
331
 
332
+ # target_models와 매칭
 
 
 
 
 
 
 
 
 
333
  filtered_models = []
334
+ for model in unique_models:
335
+ if model['id'] in target_models:
336
+ model['rank'] = len(filtered_models) + 1
337
+ filtered_models.append(model)
338
+ print(f"Matched model: {model['id']}")
 
 
 
339
 
340
+ print(f"Matched {len(filtered_models)} models out of {len(target_models)} targets")
341
 
342
  if not filtered_models:
343
  return create_error_plot(), "<div>선택된 모델의 데이터를 찾을 수 없습니다.</div>", pd.DataFrame()
344
 
 
345
  progress(0.3, desc="Creating visualization...")
346
 
347
  # 시각화 생성
 
352
  downloads = [model.get('downloads', 0) for model in filtered_models]
353
  likes = [model.get('likes', 0) for model in filtered_models]
354
 
355
+ # 다운로드 수를 기준으로 순위 재계산
356
  sorted_models = sorted(filtered_models, key=lambda x: x.get('downloads', 0), reverse=True)
357
  for idx, model in enumerate(sorted_models):
358
  model['rank'] = idx + 1
 
404
  """
405
 
406
  for model in sorted_models:
407
+ model_id = model['id']
408
+ rank = model['rank']
409
  downloads = model.get('downloads', 0)
410
  likes = model.get('likes', 0)
411
 
 
440
 
441
  # 데이터프레임 생성
442
  df = pd.DataFrame([{
443
+ 'Rank': model['rank'],
444
+ 'Model ID': model['id'],
445
  'Downloads': model.get('downloads', 'N/A'),
446
  'Likes': model.get('likes', 'N/A'),
447
+ 'URL': target_models[model['id']]
448
  } for model in sorted_models])
449
 
450
  progress(1.0, desc="Complete!")