Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -436,7 +436,7 @@ def get_card(item: dict, index: int, card_type: str = "space") -> str:
|
|
436 |
</div>
|
437 |
"""
|
438 |
|
439 |
-
def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
|
440 |
"""ํธ๋ ๋ฉ ์คํ์ด์ค ๊ฐ์ ธ์ค๊ธฐ"""
|
441 |
url = "https://huggingface.co/api/spaces"
|
442 |
|
@@ -444,13 +444,31 @@ def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
|
|
444 |
progress(0, desc="Fetching spaces data...")
|
445 |
params = {
|
446 |
'full': 'true',
|
447 |
-
'limit':
|
|
|
448 |
}
|
449 |
|
450 |
response = requests.get(url, params=params)
|
451 |
response.raise_for_status()
|
452 |
spaces = response.json()
|
453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
progress(0.1, desc="Creating gallery...")
|
455 |
html_content = """
|
456 |
<div style='padding: 20px; background: #f5f5f5;'>
|
@@ -459,18 +477,18 @@ def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
|
|
459 |
|
460 |
for idx, space in enumerate(spaces):
|
461 |
html_content += get_card(space, idx, "space")
|
462 |
-
progress((0.1 + 0.9 * idx/
|
463 |
|
464 |
html_content += "</div></div>"
|
465 |
|
466 |
progress(1.0, desc="Complete!")
|
467 |
-
return html_content, "
|
468 |
|
469 |
except Exception as e:
|
470 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
471 |
return error_html, f"Error: {str(e)}"
|
472 |
|
473 |
-
def get_models(progress=gr.Progress()) -> Tuple[str, str]:
|
474 |
"""์ธ๊ธฐ ๋ชจ๋ธ ๊ฐ์ ธ์ค๊ธฐ"""
|
475 |
url = "https://huggingface.co/api/models"
|
476 |
|
@@ -478,12 +496,30 @@ def get_models(progress=gr.Progress()) -> Tuple[str, str]:
|
|
478 |
progress(0, desc="Fetching models data...")
|
479 |
params = {
|
480 |
'full': 'true',
|
481 |
-
'limit':
|
|
|
482 |
}
|
483 |
response = requests.get(url, params=params)
|
484 |
response.raise_for_status()
|
485 |
models = response.json()
|
486 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
487 |
progress(0.1, desc="Creating gallery...")
|
488 |
html_content = """
|
489 |
<div style='padding: 20px; background: #f5f5f5;'>
|
@@ -492,18 +528,18 @@ def get_models(progress=gr.Progress()) -> Tuple[str, str]:
|
|
492 |
|
493 |
for idx, model in enumerate(models):
|
494 |
html_content += get_card(model, idx, "model")
|
495 |
-
progress((0.1 + 0.9 * idx/
|
496 |
|
497 |
html_content += "</div></div>"
|
498 |
|
499 |
progress(1.0, desc="Complete!")
|
500 |
-
return html_content, "
|
501 |
|
502 |
except Exception as e:
|
503 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
504 |
return error_html, f"Error: {str(e)}"
|
505 |
|
506 |
-
def get_datasets(progress=gr.Progress()) -> Tuple[str, str]:
|
507 |
"""์ธ๊ธฐ ๋ฐ์ดํฐ์
๊ฐ์ ธ์ค๊ธฐ"""
|
508 |
url = "https://huggingface.co/api/datasets"
|
509 |
|
@@ -511,12 +547,30 @@ def get_datasets(progress=gr.Progress()) -> Tuple[str, str]:
|
|
511 |
progress(0, desc="Fetching datasets data...")
|
512 |
params = {
|
513 |
'full': 'true',
|
514 |
-
'limit':
|
|
|
515 |
}
|
516 |
response = requests.get(url, params=params)
|
517 |
response.raise_for_status()
|
518 |
datasets = response.json()
|
519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
progress(0.1, desc="Creating gallery...")
|
521 |
html_content = """
|
522 |
<div style='padding: 20px; background: #f5f5f5;'>
|
@@ -525,80 +579,161 @@ def get_datasets(progress=gr.Progress()) -> Tuple[str, str]:
|
|
525 |
|
526 |
for idx, dataset in enumerate(datasets):
|
527 |
html_content += get_card(dataset, idx, "dataset")
|
528 |
-
progress((0.1 + 0.9 * idx/
|
529 |
|
530 |
html_content += "</div></div>"
|
531 |
|
532 |
progress(1.0, desc="Complete!")
|
533 |
-
return html_content, "
|
534 |
|
535 |
except Exception as e:
|
536 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
537 |
return error_html, f"Error: {str(e)}"
|
538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
def create_interface():
|
540 |
-
"""Gradio ์ธํฐํ์ด์ค ์์ฑ"""
|
541 |
with gr.Blocks(title="HuggingFace Trending Board") as interface:
|
542 |
gr.Markdown("# ๐ค HuggingFace Trending TOP 300 Board")
|
543 |
|
544 |
with gr.Tabs() as tabs:
|
545 |
# Spaces ํญ
|
546 |
with gr.Tab("๐ฏ Trending Spaces"):
|
547 |
-
gr.Markdown("Shows top 300 trending spaces with AI ratings")
|
548 |
with gr.Row():
|
549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
spaces_gallery = gr.HTML()
|
551 |
spaces_status = gr.Markdown("Ready")
|
552 |
|
553 |
# Models ํญ
|
554 |
with gr.Tab("๐ค Trending Models"):
|
555 |
-
gr.Markdown("Shows top 300 trending models with AI ratings")
|
556 |
with gr.Row():
|
557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
models_gallery = gr.HTML()
|
559 |
models_status = gr.Markdown("Ready")
|
560 |
|
561 |
# Datasets ํญ
|
562 |
with gr.Tab("๐ Trending Datasets"):
|
563 |
-
gr.Markdown("Shows top 300 trending datasets with AI ratings")
|
564 |
with gr.Row():
|
565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
datasets_gallery = gr.HTML()
|
567 |
datasets_status = gr.Markdown("Ready")
|
568 |
-
|
569 |
# Event handlers
|
570 |
spaces_refresh_btn.click(
|
571 |
fn=get_trending_spaces,
|
572 |
-
|
573 |
-
|
574 |
)
|
575 |
|
576 |
models_refresh_btn.click(
|
577 |
fn=get_models,
|
578 |
-
|
579 |
-
|
580 |
)
|
581 |
|
582 |
datasets_refresh_btn.click(
|
583 |
fn=get_datasets,
|
584 |
-
|
585 |
-
|
586 |
)
|
587 |
|
588 |
-
#
|
589 |
-
|
590 |
fn=get_trending_spaces,
|
|
|
591 |
outputs=[spaces_gallery, spaces_status]
|
592 |
)
|
593 |
-
|
|
|
594 |
fn=get_models,
|
|
|
595 |
outputs=[models_gallery, models_status]
|
596 |
)
|
597 |
-
|
|
|
598 |
fn=get_datasets,
|
|
|
599 |
outputs=[datasets_gallery, datasets_status]
|
600 |
)
|
601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
return interface
|
603 |
|
604 |
if __name__ == "__main__":
|
|
|
436 |
</div>
|
437 |
"""
|
438 |
|
439 |
+
def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress()) -> Tuple[str, str]:
|
440 |
"""ํธ๋ ๋ฉ ์คํ์ด์ค ๊ฐ์ ธ์ค๊ธฐ"""
|
441 |
url = "https://huggingface.co/api/spaces"
|
442 |
|
|
|
444 |
progress(0, desc="Fetching spaces data...")
|
445 |
params = {
|
446 |
'full': 'true',
|
447 |
+
'limit': 1000, # ๊ฒ์์ ์ํด ๋ ๋ง์ ํญ๋ชฉ ๋ก๋
|
448 |
+
'search': search_query
|
449 |
}
|
450 |
|
451 |
response = requests.get(url, params=params)
|
452 |
response.raise_for_status()
|
453 |
spaces = response.json()
|
454 |
|
455 |
+
# ๊ฒ์์ด๋ก ํํฐ๋ง
|
456 |
+
if search_query:
|
457 |
+
spaces = [space for space in spaces if search_query.lower() in
|
458 |
+
(space.get('id', '') + space.get('title', '')).lower()]
|
459 |
+
|
460 |
+
# ์ ๋ ฌ
|
461 |
+
if sort_by == "rising_rate":
|
462 |
+
spaces.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
|
463 |
+
elif sort_by == "popularity":
|
464 |
+
spaces.sort(key=lambda x: get_popularity_grade(
|
465 |
+
int(str(x.get('likes', '0')).replace(',', '')),
|
466 |
+
calculate_rising_rate(x.get('createdAt', ''), 0))[1],
|
467 |
+
reverse=True)
|
468 |
+
|
469 |
+
# ์์ 300๊ฐ๋ง ์ ํ
|
470 |
+
spaces = spaces[:300]
|
471 |
+
|
472 |
progress(0.1, desc="Creating gallery...")
|
473 |
html_content = """
|
474 |
<div style='padding: 20px; background: #f5f5f5;'>
|
|
|
477 |
|
478 |
for idx, space in enumerate(spaces):
|
479 |
html_content += get_card(space, idx, "space")
|
480 |
+
progress((0.1 + 0.9 * idx/len(spaces)), desc=f"Loading space {idx+1}/{len(spaces)}...")
|
481 |
|
482 |
html_content += "</div></div>"
|
483 |
|
484 |
progress(1.0, desc="Complete!")
|
485 |
+
return html_content, f"Found {len(spaces)} spaces"
|
486 |
|
487 |
except Exception as e:
|
488 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
489 |
return error_html, f"Error: {str(e)}"
|
490 |
|
491 |
+
def get_models(search_query="", sort_by="rank", progress=gr.Progress()) -> Tuple[str, str]:
|
492 |
"""์ธ๊ธฐ ๋ชจ๋ธ ๊ฐ์ ธ์ค๊ธฐ"""
|
493 |
url = "https://huggingface.co/api/models"
|
494 |
|
|
|
496 |
progress(0, desc="Fetching models data...")
|
497 |
params = {
|
498 |
'full': 'true',
|
499 |
+
'limit': 1000,
|
500 |
+
'search': search_query
|
501 |
}
|
502 |
response = requests.get(url, params=params)
|
503 |
response.raise_for_status()
|
504 |
models = response.json()
|
505 |
|
506 |
+
# ๊ฒ์์ด๋ก ํํฐ๋ง
|
507 |
+
if search_query:
|
508 |
+
models = [model for model in models if search_query.lower() in
|
509 |
+
(model.get('id', '') + model.get('title', '')).lower()]
|
510 |
+
|
511 |
+
# ์ ๋ ฌ
|
512 |
+
if sort_by == "rising_rate":
|
513 |
+
models.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
|
514 |
+
elif sort_by == "popularity":
|
515 |
+
models.sort(key=lambda x: get_popularity_grade(
|
516 |
+
int(str(x.get('likes', '0')).replace(',', '')),
|
517 |
+
calculate_rising_rate(x.get('createdAt', ''), 0))[1],
|
518 |
+
reverse=True)
|
519 |
+
|
520 |
+
# ์์ 300๊ฐ๋ง ์ ํ
|
521 |
+
models = models[:300]
|
522 |
+
|
523 |
progress(0.1, desc="Creating gallery...")
|
524 |
html_content = """
|
525 |
<div style='padding: 20px; background: #f5f5f5;'>
|
|
|
528 |
|
529 |
for idx, model in enumerate(models):
|
530 |
html_content += get_card(model, idx, "model")
|
531 |
+
progress((0.1 + 0.9 * idx/len(models)), desc=f"Loading model {idx+1}/{len(models)}...")
|
532 |
|
533 |
html_content += "</div></div>"
|
534 |
|
535 |
progress(1.0, desc="Complete!")
|
536 |
+
return html_content, f"Found {len(models)} models"
|
537 |
|
538 |
except Exception as e:
|
539 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
540 |
return error_html, f"Error: {str(e)}"
|
541 |
|
542 |
+
def get_datasets(search_query="", sort_by="rank", progress=gr.Progress()) -> Tuple[str, str]:
|
543 |
"""์ธ๊ธฐ ๋ฐ์ดํฐ์
๊ฐ์ ธ์ค๊ธฐ"""
|
544 |
url = "https://huggingface.co/api/datasets"
|
545 |
|
|
|
547 |
progress(0, desc="Fetching datasets data...")
|
548 |
params = {
|
549 |
'full': 'true',
|
550 |
+
'limit': 1000,
|
551 |
+
'search': search_query
|
552 |
}
|
553 |
response = requests.get(url, params=params)
|
554 |
response.raise_for_status()
|
555 |
datasets = response.json()
|
556 |
|
557 |
+
# ๊ฒ์์ด๋ก ํํฐ๋ง
|
558 |
+
if search_query:
|
559 |
+
datasets = [dataset for dataset in datasets if search_query.lower() in
|
560 |
+
(dataset.get('id', '') + dataset.get('title', '')).lower()]
|
561 |
+
|
562 |
+
# ์ ๋ ฌ
|
563 |
+
if sort_by == "rising_rate":
|
564 |
+
datasets.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
|
565 |
+
elif sort_by == "popularity":
|
566 |
+
datasets.sort(key=lambda x: get_popularity_grade(
|
567 |
+
int(str(x.get('likes', '0')).replace(',', '')),
|
568 |
+
calculate_rising_rate(x.get('createdAt', ''), 0))[1],
|
569 |
+
reverse=True)
|
570 |
+
|
571 |
+
# ์์ 300๊ฐ๋ง ์ ํ
|
572 |
+
datasets = datasets[:300]
|
573 |
+
|
574 |
progress(0.1, desc="Creating gallery...")
|
575 |
html_content = """
|
576 |
<div style='padding: 20px; background: #f5f5f5;'>
|
|
|
579 |
|
580 |
for idx, dataset in enumerate(datasets):
|
581 |
html_content += get_card(dataset, idx, "dataset")
|
582 |
+
progress((0.1 + 0.9 * idx/len(datasets)), desc=f"Loading dataset {idx+1}/{len(datasets)}...")
|
583 |
|
584 |
html_content += "</div></div>"
|
585 |
|
586 |
progress(1.0, desc="Complete!")
|
587 |
+
return html_content, f"Found {len(datasets)} datasets"
|
588 |
|
589 |
except Exception as e:
|
590 |
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
591 |
return error_html, f"Error: {str(e)}"
|
592 |
|
593 |
+
# ์ ๋ ฌ ํจ์ ์ถ๊ฐ
|
594 |
+
def sort_items(items, sort_by):
|
595 |
+
if sort_by == "rank":
|
596 |
+
return items # ์ด๋ฏธ ์์๋๋ก ์ ๋ ฌ๋์ด ์์
|
597 |
+
elif sort_by == "rising_rate":
|
598 |
+
return sorted(items, key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
|
599 |
+
elif sort_by == "popularity":
|
600 |
+
return sorted(items, key=lambda x: get_popularity_grade(int(str(x.get('likes', '0')).replace(',', '')),
|
601 |
+
calculate_rising_rate(x.get('createdAt', ''), 0))[1], reverse=True)
|
602 |
+
return items
|
603 |
+
|
604 |
+
# API ํธ์ถ ํจ์ ์์
|
605 |
+
def fetch_items(item_type, search_query="", sort_by="rank", limit=1000):
|
606 |
+
"""์์ดํ
๊ฐ์ ธ์ค๊ธฐ (spaces/models/datasets)"""
|
607 |
+
base_url = f"https://huggingface.co/api/{item_type}"
|
608 |
+
params = {
|
609 |
+
'full': 'true',
|
610 |
+
'limit': limit,
|
611 |
+
'search': search_query
|
612 |
+
}
|
613 |
+
|
614 |
+
try:
|
615 |
+
response = requests.get(base_url, params=params)
|
616 |
+
response.raise_for_status()
|
617 |
+
items = response.json()
|
618 |
+
|
619 |
+
# ๊ฒ์์ด๋ก ํํฐ๋ง
|
620 |
+
if search_query:
|
621 |
+
items = [item for item in items if search_query.lower() in
|
622 |
+
(item.get('id', '') + item.get('title', '')).lower()]
|
623 |
+
|
624 |
+
# ์ ๋ ฌ
|
625 |
+
items = sort_items(items, sort_by)
|
626 |
+
|
627 |
+
return items[:300] # ์์ 300๊ฐ๋ง ๋ฐํ
|
628 |
+
except Exception as e:
|
629 |
+
print(f"Error fetching items: {e}")
|
630 |
+
return []
|
631 |
+
|
632 |
+
# ์ธํฐํ์ด์ค ์์
|
633 |
def create_interface():
|
|
|
634 |
with gr.Blocks(title="HuggingFace Trending Board") as interface:
|
635 |
gr.Markdown("# ๐ค HuggingFace Trending TOP 300 Board")
|
636 |
|
637 |
with gr.Tabs() as tabs:
|
638 |
# Spaces ํญ
|
639 |
with gr.Tab("๐ฏ Trending Spaces"):
|
|
|
640 |
with gr.Row():
|
641 |
+
spaces_search = gr.Textbox(label="Search Spaces", placeholder="Enter search terms...")
|
642 |
+
spaces_sort = gr.Radio(
|
643 |
+
choices=["rank", "rising_rate", "popularity"],
|
644 |
+
value="rank",
|
645 |
+
label="Sort by",
|
646 |
+
interactive=True
|
647 |
+
)
|
648 |
+
spaces_refresh_btn = gr.Button("Refresh", variant="primary")
|
649 |
spaces_gallery = gr.HTML()
|
650 |
spaces_status = gr.Markdown("Ready")
|
651 |
|
652 |
# Models ํญ
|
653 |
with gr.Tab("๐ค Trending Models"):
|
|
|
654 |
with gr.Row():
|
655 |
+
models_search = gr.Textbox(label="Search Models", placeholder="Enter search terms...")
|
656 |
+
models_sort = gr.Radio(
|
657 |
+
choices=["rank", "rising_rate", "popularity"],
|
658 |
+
value="rank",
|
659 |
+
label="Sort by",
|
660 |
+
interactive=True
|
661 |
+
)
|
662 |
+
models_refresh_btn = gr.Button("Refresh", variant="primary")
|
663 |
models_gallery = gr.HTML()
|
664 |
models_status = gr.Markdown("Ready")
|
665 |
|
666 |
# Datasets ํญ
|
667 |
with gr.Tab("๐ Trending Datasets"):
|
|
|
668 |
with gr.Row():
|
669 |
+
datasets_search = gr.Textbox(label="Search Datasets", placeholder="Enter search terms...")
|
670 |
+
datasets_sort = gr.Radio(
|
671 |
+
choices=["rank", "rising_rate", "popularity"],
|
672 |
+
value="rank",
|
673 |
+
label="Sort by",
|
674 |
+
interactive=True
|
675 |
+
)
|
676 |
+
datasets_refresh_btn = gr.Button("Refresh", variant="primary")
|
677 |
datasets_gallery = gr.HTML()
|
678 |
datasets_status = gr.Markdown("Ready")
|
679 |
+
|
680 |
# Event handlers
|
681 |
spaces_refresh_btn.click(
|
682 |
fn=get_trending_spaces,
|
683 |
+
inputs=[spaces_search, spaces_sort],
|
684 |
+
outputs=[spaces_gallery, spaces_status]
|
685 |
)
|
686 |
|
687 |
models_refresh_btn.click(
|
688 |
fn=get_models,
|
689 |
+
inputs=[models_search, models_sort],
|
690 |
+
outputs=[models_gallery, models_status]
|
691 |
)
|
692 |
|
693 |
datasets_refresh_btn.click(
|
694 |
fn=get_datasets,
|
695 |
+
inputs=[datasets_search, datasets_sort],
|
696 |
+
outputs=[datasets_gallery, datasets_status]
|
697 |
)
|
698 |
|
699 |
+
# ๊ฒ์์ด ๋ณ๊ฒฝ ์ ์๋ ์๋ก๊ณ ์นจ
|
700 |
+
spaces_search.change(
|
701 |
fn=get_trending_spaces,
|
702 |
+
inputs=[spaces_search, spaces_sort],
|
703 |
outputs=[spaces_gallery, spaces_status]
|
704 |
)
|
705 |
+
|
706 |
+
models_search.change(
|
707 |
fn=get_models,
|
708 |
+
inputs=[models_search, models_sort],
|
709 |
outputs=[models_gallery, models_status]
|
710 |
)
|
711 |
+
|
712 |
+
datasets_search.change(
|
713 |
fn=get_datasets,
|
714 |
+
inputs=[datasets_search, datasets_sort],
|
715 |
outputs=[datasets_gallery, datasets_status]
|
716 |
)
|
717 |
+
|
718 |
+
# ์ ๋ ฌ ๋ฐฉ์ ๋ณ๊ฒฝ ์ ์๋ ์๋ก๊ณ ์นจ
|
719 |
+
spaces_sort.change(
|
720 |
+
fn=get_trending_spaces,
|
721 |
+
inputs=[spaces_search, spaces_sort],
|
722 |
+
outputs=[spaces_gallery, spaces_status]
|
723 |
+
)
|
724 |
+
|
725 |
+
models_sort.change(
|
726 |
+
fn=get_models,
|
727 |
+
inputs=[models_search, models_sort],
|
728 |
+
outputs=[models_gallery, models_status]
|
729 |
+
)
|
730 |
+
|
731 |
+
datasets_sort.change(
|
732 |
+
fn=get_datasets,
|
733 |
+
inputs=[datasets_search, datasets_sort],
|
734 |
+
outputs=[datasets_gallery, datasets_status]
|
735 |
+
)
|
736 |
+
|
737 |
return interface
|
738 |
|
739 |
if __name__ == "__main__":
|