openfree commited on
Commit
8e6fe54
โ€ข
1 Parent(s): f3da4e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -153
app.py CHANGED
@@ -466,34 +466,27 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
466
  progress(0, desc="Fetching spaces data...")
467
  params = {
468
  'full': 'true',
469
- 'limit': 10 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
470
  }
471
 
472
  response = requests.get(url, params=params)
473
  response.raise_for_status()
474
  spaces = response.json()
475
 
476
- # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€์ƒ‰์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
477
  if search_query:
478
- filtered_spaces = []
479
- # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
480
- params['limit'] = 10
481
- response = requests.get(url, params=params)
482
- all_spaces = response.json()
483
-
484
- filtered_spaces = [space for space in all_spaces if search_query.lower() in
485
- (space.get('id', '') + space.get('title', '')).lower()]
486
- spaces = filtered_spaces[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
487
-
488
- # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
489
- if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
490
- if sort_by == "rising_rate":
491
- spaces.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
492
- elif sort_by == "popularity":
493
- spaces.sort(key=lambda x: get_popularity_grade(
494
- int(str(x.get('likes', '0')).replace(',', '')),
495
- calculate_rising_rate(x.get('createdAt', ''), 0))[1],
496
- reverse=True)
497
 
498
  progress(0.1, desc="Creating gallery...")
499
  html_content = """
@@ -522,33 +515,26 @@ def get_models(search_query="", sort_by="rank", progress=gr.Progress()) -> Tuple
522
  progress(0, desc="Fetching models data...")
523
  params = {
524
  'full': 'true',
525
- 'limit': 300 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
526
  }
527
  response = requests.get(url, params=params)
528
  response.raise_for_status()
529
  models = response.json()
530
 
531
- # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€์ƒ‰์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
532
  if search_query:
533
- filtered_models = []
534
- # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
535
- params['limit'] = 300
536
- response = requests.get(url, params=params)
537
- all_models = response.json()
538
-
539
- filtered_models = [model for model in all_models if search_query.lower() in
540
- (model.get('id', '') + model.get('title', '')).lower()]
541
- models = filtered_models[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
542
-
543
- # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
544
- if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
545
- if sort_by == "rising_rate":
546
- models.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
547
- elif sort_by == "popularity":
548
- models.sort(key=lambda x: get_popularity_grade(
549
- int(str(x.get('likes', '0')).replace(',', '')),
550
- calculate_rising_rate(x.get('createdAt', ''), 0))[1],
551
- reverse=True)
552
 
553
  progress(0.1, desc="Creating gallery...")
554
  html_content = """
@@ -577,33 +563,26 @@ def get_datasets(search_query="", sort_by="rank", progress=gr.Progress()) -> Tup
577
  progress(0, desc="Fetching datasets data...")
578
  params = {
579
  'full': 'true',
580
- 'limit': 300 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
581
  }
582
  response = requests.get(url, params=params)
583
  response.raise_for_status()
584
  datasets = response.json()
585
 
586
- # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€๏ฟฝ๏ฟฝ๏ฟฝ์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
587
  if search_query:
588
- filtered_datasets = []
589
- # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
590
- params['limit'] = 300
591
- response = requests.get(url, params=params)
592
- all_datasets = response.json()
593
-
594
- filtered_datasets = [dataset for dataset in all_datasets if search_query.lower() in
595
- (dataset.get('id', '') + dataset.get('title', '')).lower()]
596
- datasets = filtered_datasets[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
597
-
598
- # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
599
- if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
600
- if sort_by == "rising_rate":
601
- datasets.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
602
- elif sort_by == "popularity":
603
- datasets.sort(key=lambda x: get_popularity_grade(
604
- int(str(x.get('likes', '0')).replace(',', '')),
605
- calculate_rising_rate(x.get('createdAt', ''), 0))[1],
606
- reverse=True)
607
 
608
  progress(0.1, desc="Creating gallery...")
609
  html_content = """
@@ -671,7 +650,7 @@ def create_interface():
671
  padding: 20px;
672
  margin: 10px 0;
673
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
674
- overflow: visible; /* ์Šคํฌ๋กค๋ฐ” ์ œ๊ฑฐ */
675
  }
676
  .search-box {
677
  border: 2px solid #e1e1e1;
@@ -686,79 +665,6 @@ def create_interface():
686
  box-shadow: 0 0 0 2px rgba(123,97,255,0.2);
687
  background: linear-gradient(135deg, #ffffff, #f0f3ff);
688
  }
689
- /* ์ •๋ ฌ ๋ฒ„ํŠผ ์ปจํ…Œ์ด๋„ˆ ์ˆ˜์ • */
690
- .sort-radio {
691
- display: inline-flex !important;
692
- gap: 15px !important;
693
- background: transparent !important;
694
- padding: 0 !important;
695
- overflow: visible !important; /* ์Šคํฌ๋กค๋ฐ” ์ œ๊ฑฐ */
696
- width: auto !important;
697
- min-width: 390px !important; /* 3๊ฐœ ๋ฒ„ํŠผ + ๊ฐ„๊ฒฉ */
698
- }
699
-
700
- /* ๋ผ๋””์˜ค ๋ฒ„ํŠผ ๊ทธ๋ฃน ์ปจํ…Œ์ด๋„ˆ */
701
- .sort-radio > div {
702
- display: flex !important;
703
- gap: 15px !important;
704
- overflow: visible !important; /* ์Šคํฌ๋กค๋ฐ” ์ œ๊ฑฐ */
705
- }
706
-
707
- /* ๊ฐ ๋ผ๋””์˜ค ๋ฒ„ํŠผ ํ•ญ๋ชฉ */
708
- .sort-radio > div > div {
709
- width: 120px !important;
710
- height: 80px !important;
711
- }
712
-
713
- /* ๋ผ๋””์˜ค ๋ฒ„ํŠผ์„ ๋ฒ„ํŠผ์ฒ˜๋Ÿผ ์Šคํƒ€์ผ๋ง */
714
- .sort-radio label {
715
- width: 120px !important;
716
- height: 80px !important;
717
- display: flex !important;
718
- align-items: center !important;
719
- justify-content: center !important;
720
- color: white !important;
721
- border: none !important;
722
- border-radius: 10px !important;
723
- cursor: pointer !important;
724
- transition: all 0.3s ease !important;
725
- font-size: 1.1em !important;
726
- text-align: center !important;
727
- padding: 10px !important;
728
- box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
729
- white-space: normal !important; /* ํ…์ŠคํŠธ ์ค„๋ฐ”๊ฟˆ ํ—ˆ์šฉ */
730
- word-break: break-word !important; /* ๊ธด ๋‹จ์–ด ์ค„๋ฐ”๊ฟˆ */
731
- line-height: 1.2 !important; /* ์ค„๊ฐ„๊ฒฉ ์กฐ์ • */
732
- }
733
-
734
- /* ์ฒซ ๋ฒˆ์งธ ๋ฒ„ํŠผ (rank) */
735
- .sort-radio > div > div:nth-child(1) label {
736
- background: linear-gradient(135deg, #4CAF50, #45a049) !important;
737
- }
738
-
739
- /* ๋‘ ๋ฒˆ์งธ ๋ฒ„ํŠผ (rising_rate) */
740
- .sort-radio > div > div:nth-child(2) label {
741
- background: linear-gradient(135deg, #2196F3, #1976D2) !important;
742
- }
743
-
744
- /* ์„ธ ๋ฒˆ์งธ ๋ฒ„ํŠผ (popularity) */
745
- .sort-radio > div > div:nth-child(3) label {
746
- background: linear-gradient(135deg, #9C27B0, #7B1FA2) !important;
747
- }
748
-
749
- /* ํ˜ธ๋ฒ„ ํšจ๊ณผ */
750
- .sort-radio label:hover {
751
- transform: translateY(-2px) !important;
752
- box-shadow: 0 6px 12px rgba(0,0,0,0.2) !important;
753
- }
754
-
755
- /* ์„ ํƒ๋œ ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
756
- .sort-radio input:checked + label {
757
- box-shadow: inset 0 2px 4px rgba(0,0,0,0.2) !important;
758
- transform: translateY(1px) !important;
759
- }
760
-
761
- /* ๋ฆฌํ”„๋ ˆ์‹œ ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
762
  .refresh-btn {
763
  background: linear-gradient(135deg, #7b61ff, #6366f1);
764
  color: white;
@@ -776,7 +682,6 @@ def create_interface():
776
  font-size: 1.2em !important;
777
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
778
  }
779
-
780
  .refresh-btn:hover {
781
  transform: translateY(-2px);
782
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
@@ -794,7 +699,6 @@ def create_interface():
794
  with gr.Tabs() as tabs:
795
  # Spaces ํƒญ
796
  with gr.Tab("๐ŸŽฏ Trending Spaces"):
797
-
798
  with gr.Row(elem_classes="search-sort-container"):
799
  with gr.Column(scale=2):
800
  spaces_search = gr.Textbox(
@@ -804,13 +708,11 @@ def create_interface():
804
  )
805
  with gr.Column(scale=2):
806
  spaces_sort = gr.Radio(
807
- choices=["Rank", "Rising Rate", "Popularity"], # ํ…์ŠคํŠธ ์ˆ˜์ •
808
- value="Rank",
809
- label="๐Ÿ“Š Sort by",
810
- interactive=True,
811
- elem_classes="sort-radio"
812
  )
813
-
814
  with gr.Column(scale=1):
815
  spaces_refresh_btn = gr.Button(
816
  "๐Ÿ”„ Refresh",
@@ -822,7 +724,6 @@ def create_interface():
822
 
823
  # Models ํƒญ
824
  with gr.Tab("๐Ÿค– Trending Models"):
825
-
826
  with gr.Row(elem_classes="search-sort-container"):
827
  with gr.Column(scale=2):
828
  models_search = gr.Textbox(
@@ -834,9 +735,8 @@ def create_interface():
834
  models_sort = gr.Radio(
835
  choices=["rank", "rising_rate", "popularity"],
836
  value="rank",
837
- label="๐Ÿ“Š Sort by",
838
- interactive=True,
839
- elem_classes="sort-radio"
840
  )
841
  with gr.Column(scale=1):
842
  models_refresh_btn = gr.Button(
@@ -849,7 +749,6 @@ def create_interface():
849
 
850
  # Datasets ํƒญ
851
  with gr.Tab("๐Ÿ“Š Trending Datasets"):
852
-
853
  with gr.Row(elem_classes="search-sort-container"):
854
  with gr.Column(scale=2):
855
  datasets_search = gr.Textbox(
@@ -861,9 +760,8 @@ def create_interface():
861
  datasets_sort = gr.Radio(
862
  choices=["rank", "rising_rate", "popularity"],
863
  value="rank",
864
- label="๐Ÿ“Š Sort by",
865
- interactive=True,
866
- elem_classes="sort-radio"
867
  )
868
  with gr.Column(scale=1):
869
  datasets_refresh_btn = gr.Button(
 
466
  progress(0, desc="Fetching spaces data...")
467
  params = {
468
  'full': 'true',
469
+ 'limit': 10
470
  }
471
 
472
  response = requests.get(url, params=params)
473
  response.raise_for_status()
474
  spaces = response.json()
475
 
476
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง
477
  if search_query:
478
+ spaces = [space for space in spaces if search_query.lower() in
479
+ (space.get('id', '') + ' ' + space.get('title', '')).lower()]
480
+
481
+ # ์ •๋ ฌ
482
+ sort_by = sort_by.lower()
483
+ if sort_by == "rising_rate":
484
+ spaces.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
485
+ elif sort_by == "popularity":
486
+ spaces.sort(key=lambda x: get_popularity_grade(
487
+ int(str(x.get('likes', '0')).replace(',', '')),
488
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
489
+ reverse=True)
 
 
 
 
 
 
 
490
 
491
  progress(0.1, desc="Creating gallery...")
492
  html_content = """
 
515
  progress(0, desc="Fetching models data...")
516
  params = {
517
  'full': 'true',
518
+ 'limit': 300
519
  }
520
  response = requests.get(url, params=params)
521
  response.raise_for_status()
522
  models = response.json()
523
 
524
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง
525
  if search_query:
526
+ models = [model for model in models if search_query.lower() in
527
+ (model.get('id', '') + ' ' + model.get('title', '')).lower()]
528
+
529
+ # ์ •๋ ฌ
530
+ sort_by = sort_by.lower()
531
+ if sort_by == "rising_rate":
532
+ models.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
533
+ elif sort_by == "popularity":
534
+ models.sort(key=lambda x: get_popularity_grade(
535
+ int(str(x.get('likes', '0')).replace(',', '')),
536
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
537
+ reverse=True)
 
 
 
 
 
 
 
538
 
539
  progress(0.1, desc="Creating gallery...")
540
  html_content = """
 
563
  progress(0, desc="Fetching datasets data...")
564
  params = {
565
  'full': 'true',
566
+ 'limit': 300
567
  }
568
  response = requests.get(url, params=params)
569
  response.raise_for_status()
570
  datasets = response.json()
571
 
572
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง
573
  if search_query:
574
+ datasets = [dataset for dataset in datasets if search_query.lower() in
575
+ (dataset.get('id', '') + ' ' + dataset.get('title', '')).lower()]
576
+
577
+ # ์ •๋ ฌ
578
+ sort_by = sort_by.lower()
579
+ if sort_by == "rising_rate":
580
+ datasets.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
581
+ elif sort_by == "popularity":
582
+ datasets.sort(key=lambda x: get_popularity_grade(
583
+ int(str(x.get('likes', '0')).replace(',', '')),
584
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
585
+ reverse=True)
 
 
 
 
 
 
 
586
 
587
  progress(0.1, desc="Creating gallery...")
588
  html_content = """
 
650
  padding: 20px;
651
  margin: 10px 0;
652
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
653
+ overflow: visible;
654
  }
655
  .search-box {
656
  border: 2px solid #e1e1e1;
 
665
  box-shadow: 0 0 0 2px rgba(123,97,255,0.2);
666
  background: linear-gradient(135deg, #ffffff, #f0f3ff);
667
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  .refresh-btn {
669
  background: linear-gradient(135deg, #7b61ff, #6366f1);
670
  color: white;
 
682
  font-size: 1.2em !important;
683
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
684
  }
 
685
  .refresh-btn:hover {
686
  transform: translateY(-2px);
687
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
 
699
  with gr.Tabs() as tabs:
700
  # Spaces ํƒญ
701
  with gr.Tab("๐ŸŽฏ Trending Spaces"):
 
702
  with gr.Row(elem_classes="search-sort-container"):
703
  with gr.Column(scale=2):
704
  spaces_search = gr.Textbox(
 
708
  )
709
  with gr.Column(scale=2):
710
  spaces_sort = gr.Radio(
711
+ choices=["rank", "rising_rate", "popularity"],
712
+ value="rank",
713
+ label="Sort by",
714
+ interactive=True
 
715
  )
 
716
  with gr.Column(scale=1):
717
  spaces_refresh_btn = gr.Button(
718
  "๐Ÿ”„ Refresh",
 
724
 
725
  # Models ํƒญ
726
  with gr.Tab("๐Ÿค– Trending Models"):
 
727
  with gr.Row(elem_classes="search-sort-container"):
728
  with gr.Column(scale=2):
729
  models_search = gr.Textbox(
 
735
  models_sort = gr.Radio(
736
  choices=["rank", "rising_rate", "popularity"],
737
  value="rank",
738
+ label="Sort by",
739
+ interactive=True
 
740
  )
741
  with gr.Column(scale=1):
742
  models_refresh_btn = gr.Button(
 
749
 
750
  # Datasets ํƒญ
751
  with gr.Tab("๐Ÿ“Š Trending Datasets"):
 
752
  with gr.Row(elem_classes="search-sort-container"):
753
  with gr.Column(scale=2):
754
  datasets_search = gr.Textbox(
 
760
  datasets_sort = gr.Radio(
761
  choices=["rank", "rising_rate", "popularity"],
762
  value="rank",
763
+ label="Sort by",
764
+ interactive=True
 
765
  )
766
  with gr.Column(scale=1):
767
  datasets_refresh_btn = gr.Button(