openfree commited on
Commit
e25383c
·
verified ·
1 Parent(s): 7f873ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -42
app.py CHANGED
@@ -318,53 +318,76 @@ def get_korea_models():
318
  return []
319
 
320
  def get_all_models(limit=1000):
321
- """페이지네이션을 사용하여 모든 모델 가져오기"""
322
  all_models = []
323
- offset = 0
324
- page_size = 1000 # API의 기본 페이지 크기
325
-
326
- # 일반 모델 가져오기
327
- while len(all_models) < limit:
328
- params = {
329
- "limit": min(page_size, limit - len(all_models)),
330
- "full": "True",
331
- "config": "True",
332
- "offset": offset
333
- }
334
-
335
- response = requests.get(
336
- "https://huggingface.co/api/models",
337
- headers={'Accept': 'application/json'},
338
- params=params
339
- )
340
-
341
- if response.status_code != 200:
342
- break
343
-
344
- models = response.json()
345
- if not models: # 더 이상 데이터가 없으면 종료
346
- break
347
-
348
- all_models.extend(models)
349
- offset += len(models)
 
 
 
 
 
 
 
 
350
 
351
- if len(models) < page_size: # 마지막 페이지면 종료
352
- break
 
 
 
 
353
 
354
- # Korea 관련 모델 추가
355
- korea_models = get_korea_models()
356
- print(f"Found {len(korea_models)} Korea-related models")
 
 
 
 
357
 
358
- # 중복 제거를 위한 ID 세트
359
- existing_ids = {model.get('id', '') for model in all_models}
 
 
 
360
 
361
- # 중복되지 않은 Korea 모델만 추가
362
- for model in korea_models:
363
- if model.get('id', '') not in existing_ids:
364
- all_models.append(model)
365
- existing_ids.add(model.get('id', ''))
 
 
 
 
366
 
367
- print(f"Total models after adding Korea-related: {len(all_models)}")
368
  return all_models[:limit]
369
 
370
  def get_models_data(progress=gr.Progress()):
@@ -372,7 +395,7 @@ def get_models_data(progress=gr.Progress()):
372
  try:
373
  progress(0, desc="Fetching models...")
374
 
375
- # 페이지네이션을 사용하여 모델 가져오기
376
  all_global_models = get_all_models(limit=1000)
377
  print(f"Actually fetched models count: {len(all_global_models)}")
378
 
 
318
  return []
319
 
320
  def get_all_models(limit=1000):
321
+ """모든 모델과 Korea 관련 모델 가져오기"""
322
  all_models = []
323
+
324
+ # 1. 일반 모델 리스트 가져오기
325
+ params = {
326
+ "limit": limit,
327
+ "full": "True",
328
+ "config": "True"
329
+ }
330
+
331
+ response = requests.get(
332
+ "https://huggingface.co/api/models",
333
+ headers={'Accept': 'application/json'},
334
+ params=params
335
+ )
336
+
337
+ if response.status_code == 200:
338
+ all_models.extend(response.json())
339
+ print(f"Fetched {len(all_models)} general models")
340
+
341
+ # 2. Korea 검색 결과 가져오기
342
+ korea_params = {
343
+ "search": "korea",
344
+ "full": "True",
345
+ "config": "True",
346
+ "limit": limit
347
+ }
348
+
349
+ korea_response = requests.get(
350
+ "https://huggingface.co/api/models",
351
+ headers={'Accept': 'application/json'},
352
+ params=korea_params
353
+ )
354
+
355
+ if korea_response.status_code == 200:
356
+ korea_models = korea_response.json()
357
+ print(f"Fetched {len(korea_models)} Korea-related models")
358
 
359
+ # 중복 제거하면서 Korea 모델 추가
360
+ existing_ids = {model.get('id', '') for model in all_models}
361
+ for model in korea_models:
362
+ if model.get('id', '') not in existing_ids:
363
+ all_models.append(model)
364
+ existing_ids.add(model.get('id', ''))
365
 
366
+ # 3. Korean 검색 결과 가져오기
367
+ korean_params = {
368
+ "search": "korean",
369
+ "full": "True",
370
+ "config": "True",
371
+ "limit": limit
372
+ }
373
 
374
+ korean_response = requests.get(
375
+ "https://huggingface.co/api/models",
376
+ headers={'Accept': 'application/json'},
377
+ params=korean_params
378
+ )
379
 
380
+ if korean_response.status_code == 200:
381
+ korean_models = korean_response.json()
382
+ print(f"Fetched {len(korean_models)} Korean-related models")
383
+
384
+ # 중복 제거하면서 Korean 모델 추가
385
+ for model in korean_models:
386
+ if model.get('id', '') not in existing_ids:
387
+ all_models.append(model)
388
+ existing_ids.add(model.get('id', ''))
389
 
390
+ print(f"Total unique models: {len(all_models)}")
391
  return all_models[:limit]
392
 
393
  def get_models_data(progress=gr.Progress()):
 
395
  try:
396
  progress(0, desc="Fetching models...")
397
 
398
+ # 모델 가져오기
399
  all_global_models = get_all_models(limit=1000)
400
  print(f"Actually fetched models count: {len(all_global_models)}")
401