Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -375,6 +375,24 @@ def get_all_models(limit=3000):
|
|
375 |
return all_models[:limit]
|
376 |
|
377 |
def get_models_data(progress=gr.Progress()):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
try:
|
379 |
progress(0, desc="Fetching models...")
|
380 |
|
@@ -393,14 +411,22 @@ def get_models_data(progress=gr.Progress()):
|
|
393 |
all_global_models = get_all_models(limit=3000)
|
394 |
korea_models = get_korea_models()
|
395 |
|
|
|
|
|
|
|
396 |
# ๋ชจ๋ ๋ชจ๋ธ ํตํฉ (์ค๋ณต ์ ๊ฑฐ)
|
397 |
all_models = all_global_models.copy()
|
398 |
existing_ids = {model.get('id', '') for model in all_global_models}
|
399 |
|
|
|
400 |
for korea_model in korea_models:
|
401 |
if korea_model.get('id', '') not in existing_ids:
|
402 |
all_models.append(korea_model)
|
403 |
existing_ids.add(korea_model.get('id', ''))
|
|
|
|
|
|
|
|
|
404 |
|
405 |
# ์๊ฐํ๋ฅผ ์ํ Figure ์์ฑ
|
406 |
fig = go.Figure()
|
@@ -418,15 +444,18 @@ def get_models_data(progress=gr.Progress()):
|
|
418 |
|
419 |
if response.status_code == 200:
|
420 |
model_data = response.json()
|
|
|
|
|
421 |
filtered_models.append({
|
422 |
'id': model_id,
|
423 |
-
'global_rank':
|
424 |
-
if m.get('id', '').strip() == model_id.strip()), 'Not in top 3000'),
|
425 |
'downloads': model_data.get('downloads', 0),
|
426 |
'likes': model_data.get('likes', 0),
|
427 |
'title': model_data.get('title', 'No Title'),
|
428 |
-
'is_korea':
|
429 |
})
|
|
|
|
|
430 |
else:
|
431 |
filtered_models.append({
|
432 |
'id': model_id,
|
|
|
375 |
return all_models[:limit]
|
376 |
|
377 |
def get_models_data(progress=gr.Progress()):
|
378 |
+
def calculate_rank(model_id, all_global_models, korea_models):
|
379 |
+
# ๊ธ๋ก๋ฒ ์์ ํ์ธ
|
380 |
+
global_rank = next((idx for idx, m in enumerate(all_global_models, 1)
|
381 |
+
if m.get('id', '').strip() == model_id.strip()), None)
|
382 |
+
|
383 |
+
# Korea ๋ชจ๋ธ์ธ ๊ฒฝ์ฐ
|
384 |
+
is_korea = any(m.get('id', '').strip() == model_id.strip() for m in korea_models)
|
385 |
+
|
386 |
+
if is_korea:
|
387 |
+
# Korea ๋ชจ๋ธ ์ค์์์ ์์ ํ์ธ
|
388 |
+
korea_rank = next((idx for idx, m in enumerate(korea_models, 1)
|
389 |
+
if m.get('id', '').strip() == model_id.strip()), None)
|
390 |
+
|
391 |
+
if korea_rank:
|
392 |
+
return min(global_rank or 3001, korea_rank + 1000), True
|
393 |
+
|
394 |
+
return global_rank if global_rank else 'Not in top 3000', is_korea
|
395 |
+
|
396 |
try:
|
397 |
progress(0, desc="Fetching models...")
|
398 |
|
|
|
411 |
all_global_models = get_all_models(limit=3000)
|
412 |
korea_models = get_korea_models()
|
413 |
|
414 |
+
print(f"Total global models fetched: {len(all_global_models)}")
|
415 |
+
print(f"Total Korea models fetched: {len(korea_models)}")
|
416 |
+
|
417 |
# ๋ชจ๋ ๋ชจ๋ธ ํตํฉ (์ค๋ณต ์ ๊ฑฐ)
|
418 |
all_models = all_global_models.copy()
|
419 |
existing_ids = {model.get('id', '') for model in all_global_models}
|
420 |
|
421 |
+
added_korea_models = 0
|
422 |
for korea_model in korea_models:
|
423 |
if korea_model.get('id', '') not in existing_ids:
|
424 |
all_models.append(korea_model)
|
425 |
existing_ids.add(korea_model.get('id', ''))
|
426 |
+
added_korea_models += 1
|
427 |
+
|
428 |
+
print(f"Added {added_korea_models} unique Korea models")
|
429 |
+
print(f"Total combined models: {len(all_models)}")
|
430 |
|
431 |
# ์๊ฐํ๋ฅผ ์ํ Figure ์์ฑ
|
432 |
fig = go.Figure()
|
|
|
444 |
|
445 |
if response.status_code == 200:
|
446 |
model_data = response.json()
|
447 |
+
rank, is_korea = calculate_rank(model_id, all_global_models, korea_models)
|
448 |
+
|
449 |
filtered_models.append({
|
450 |
'id': model_id,
|
451 |
+
'global_rank': rank,
|
|
|
452 |
'downloads': model_data.get('downloads', 0),
|
453 |
'likes': model_data.get('likes', 0),
|
454 |
'title': model_data.get('title', 'No Title'),
|
455 |
+
'is_korea': is_korea
|
456 |
})
|
457 |
+
|
458 |
+
print(f"Model {model_id}: Rank={rank}, Is Korea={is_korea}")
|
459 |
else:
|
460 |
filtered_models.append({
|
461 |
'id': model_id,
|