openfree commited on
Commit
e66b234
โ€ข
1 Parent(s): 7181c87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -51
app.py CHANGED
@@ -444,30 +444,34 @@ def get_trending_spaces(search_query="", sort_by="rank", progress=gr.Progress())
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 = """
@@ -496,29 +500,33 @@ def get_models(search_query="", sort_by="rank", progress=gr.Progress()) -> Tuple
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 = """
@@ -547,29 +555,33 @@ def get_datasets(search_query="", sort_by="rank", progress=gr.Progress()) -> Tup
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 = """
 
444
  progress(0, desc="Fetching spaces data...")
445
  params = {
446
  'full': 'true',
447
+ 'limit': 10 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
 
448
  }
449
 
450
  response = requests.get(url, params=params)
451
  response.raise_for_status()
452
  spaces = response.json()
453
 
454
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€์ƒ‰์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
455
  if search_query:
456
+ filtered_spaces = []
457
+ # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
458
+ params['limit'] = 1000
459
+ response = requests.get(url, params=params)
460
+ all_spaces = response.json()
461
+
462
+ filtered_spaces = [space for space in all_spaces if search_query.lower() in
463
+ (space.get('id', '') + space.get('title', '')).lower()]
464
+ spaces = filtered_spaces[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
465
+
466
+ # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
467
+ if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
468
+ if sort_by == "rising_rate":
469
+ spaces.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
470
+ elif sort_by == "popularity":
471
+ spaces.sort(key=lambda x: get_popularity_grade(
472
+ int(str(x.get('likes', '0')).replace(',', '')),
473
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
474
+ reverse=True)
475
 
476
  progress(0.1, desc="Creating gallery...")
477
  html_content = """
 
500
  progress(0, desc="Fetching models data...")
501
  params = {
502
  'full': 'true',
503
+ 'limit': 300 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
 
504
  }
505
  response = requests.get(url, params=params)
506
  response.raise_for_status()
507
  models = response.json()
508
 
509
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€์ƒ‰์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
510
  if search_query:
511
+ filtered_models = []
512
+ # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
513
+ params['limit'] = 1000
514
+ response = requests.get(url, params=params)
515
+ all_models = response.json()
516
+
517
+ filtered_models = [model for model in all_models if search_query.lower() in
518
+ (model.get('id', '') + model.get('title', '')).lower()]
519
+ models = filtered_models[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
520
+
521
+ # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
522
+ if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
523
+ if sort_by == "rising_rate":
524
+ models.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
525
+ elif sort_by == "popularity":
526
+ models.sort(key=lambda x: get_popularity_grade(
527
+ int(str(x.get('likes', '0')).replace(',', '')),
528
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
529
+ reverse=True)
530
 
531
  progress(0.1, desc="Creating gallery...")
532
  html_content = """
 
555
  progress(0, desc="Fetching datasets data...")
556
  params = {
557
  'full': 'true',
558
+ 'limit': 300 # ๊ธฐ๋ณธ 300๊ฐœ ์œ ์ง€
 
559
  }
560
  response = requests.get(url, params=params)
561
  response.raise_for_status()
562
  datasets = response.json()
563
 
564
+ # ๊ฒ€์ƒ‰์–ด๋กœ ํ•„ํ„ฐ๋ง (๊ฒ€์ƒ‰์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ)
565
  if search_query:
566
+ filtered_datasets = []
567
+ # ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (๊ฒ€์ƒ‰์šฉ)
568
+ params['limit'] = 1000
569
+ response = requests.get(url, params=params)
570
+ all_datasets = response.json()
571
+
572
+ filtered_datasets = [dataset for dataset in all_datasets if search_query.lower() in
573
+ (dataset.get('id', '') + dataset.get('title', '')).lower()]
574
+ datasets = filtered_datasets[:300] # ์ƒ์œ„ 300๊ฐœ๋งŒ ์œ ์ง€
575
+
576
+ # ์ •๋ ฌ (rank๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ)
577
+ if sort_by != "rank": # rank์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ˆœ์„œ ์œ ์ง€
578
+ if sort_by == "rising_rate":
579
+ datasets.sort(key=lambda x: calculate_rising_rate(x.get('createdAt', ''), 0), reverse=True)
580
+ elif sort_by == "popularity":
581
+ datasets.sort(key=lambda x: get_popularity_grade(
582
+ int(str(x.get('likes', '0')).replace(',', '')),
583
+ calculate_rising_rate(x.get('createdAt', ''), 0))[1],
584
+ reverse=True)
585
 
586
  progress(0.1, desc="Creating gallery...")
587
  html_content = """