openfree commited on
Commit
f60c972
ยท
verified ยท
1 Parent(s): 58eb2f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +125 -24
app.py CHANGED
@@ -85,6 +85,124 @@ def take_screenshot(url):
85
  if 'driver' in locals():
86
  driver.quit()
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  def get_hardware_info(item: dict) -> tuple:
89
  """ํ•˜๋“œ์›จ์–ด ์ •๋ณด ์ถ”์ถœ"""
90
  try:
@@ -120,7 +238,7 @@ def get_hardware_info(item: dict) -> tuple:
120
  except Exception as e:
121
  print(f"Error parsing hardware info: {str(e)}")
122
  return 'Standard', 'None', 'N/A'
123
-
124
  def get_card(item: dict, index: int, card_type: str = "space") -> str:
125
  """ํ†ตํ•ฉ ์นด๋“œ HTML ์ƒ์„ฑ"""
126
  item_id = item.get('id', '')
@@ -141,15 +259,10 @@ def get_card(item: dict, index: int, card_type: str = "space") -> str:
141
  pipeline_tag = item.get('pipeline_tag', '')
142
  license = item.get('license', '')
143
  sdk = item.get('sdk', 'N/A')
144
-
145
- # ํ•˜๋“œ์›จ์–ด ์š”๊ตฌ์‚ฌํ•ญ ์ฒ˜๋ฆฌ
146
- hardware = item.get('hardware', {})
147
- cpu_info = hardware.get('cpu', 'Standard')
148
- gpu_info = hardware.get('gpu', 'None')
149
- if isinstance(gpu_info, dict):
150
- gpu_type = gpu_info.get('type', 'N/A')
151
- gpu_memory = gpu_info.get('memory', 'N/A')
152
- gpu_info = f"{gpu_type} ({gpu_memory}GB)"
153
 
154
  # ์นด๋“œ ํƒ€์ž…๋ณ„ ๊ทธ๋ผ๋ฐ์ด์…˜ ์„ค์ •
155
  if card_type == "space":
@@ -366,28 +479,16 @@ def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
366
 
367
  try:
368
  progress(0, desc="Fetching spaces data...")
369
- # ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๋„๋ก ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€
370
  params = {
371
  'full': 'true',
372
- 'limit': 10,
373
- 'hardware': 'true',
374
- 'runtime': 'true' # runtime ์ •๋ณด ํฌํ•จ
375
  }
376
- headers = {
377
- 'Accept': 'application/json'
378
- }
379
-
380
- response = requests.get(url, params=params, headers=headers)
381
  response.raise_for_status()
382
  spaces = response.json()
383
 
384
- # ๋””๋ฒ„๊ทธ์šฉ ์ถœ๋ ฅ
385
- print("First space full info:", spaces[0])
386
-
387
  # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
388
  top_spaces = spaces[:10]
389
-
390
-
391
 
392
  progress(0.1, desc="Creating gallery...")
393
  html_content = """
 
85
  if 'driver' in locals():
86
  driver.quit()
87
 
88
+ from datetime import datetime, timedelta
89
+
90
+ def calculate_rising_rate(created_date: str, rank: int) -> int:
91
+ """AI Rising Rate ๊ณ„์‚ฐ"""
92
+ # ์ƒ์„ฑ์ผ ๊ธฐ์ค€ ์ ์ˆ˜ ๊ณ„์‚ฐ
93
+ created = datetime.strptime(created_date.split('T')[0], '%Y-%m-%d')
94
+ today = datetime.now()
95
+ days_diff = (today - created).days
96
+ date_score = max(0, 300 - days_diff) # ์ตœ๋Œ€ 300์ 
97
+
98
+ # ์ˆœ์œ„ ๊ธฐ์ค€ ์ ์ˆ˜ ๊ณ„์‚ฐ
99
+ rank_score = max(0, 300 - rank) # ์ตœ๋Œ€ 300์ 
100
+
101
+ # ์ด์  ๊ณ„์‚ฐ
102
+ total_score = date_score + rank_score
103
+
104
+ # ๋ณ„ ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ (0~5)
105
+ if total_score <= 100:
106
+ stars = 1
107
+ elif total_score <= 200:
108
+ stars = 2
109
+ elif total_score <= 300:
110
+ stars = 3
111
+ elif total_score <= 400:
112
+ stars = 4
113
+ else:
114
+ stars = 5
115
+
116
+ return stars
117
+
118
+ def get_popularity_grade(likes: int, stars: int) -> tuple:
119
+ """AI Popularity Score ๋“ฑ๊ธ‰ ๊ณ„์‚ฐ"""
120
+ # ๊ธฐ๋ณธ ์ ์ˆ˜ (likes)
121
+ base_score = min(likes, 10000) # ์ตœ๋Œ€ 10000์ 
122
+
123
+ # ๋ณ„์  ์ถ”๊ฐ€ ์ ์ˆ˜ (๋ณ„ ํ•˜๋‚˜๋‹น 500์ )
124
+ star_score = stars * 500
125
+
126
+ # ์ด์ 
127
+ total_score = base_score + star_score
128
+
129
+ # ๋“ฑ๊ธ‰ ํ…Œ์ด๋ธ” (18๋‹จ๊ณ„)
130
+ grades = [
131
+ (9000, "AAA+"), (8500, "AAA"), (8000, "AAA-"),
132
+ (7500, "AA+"), (7000, "AA"), (6500, "AA-"),
133
+ (6000, "A+"), (5500, "A"), (5000, "A-"),
134
+ (4500, "BBB+"), (4000, "BBB"), (3500, "BBB-"),
135
+ (3000, "BB+"), (2500, "BB"), (2000, "BB-"),
136
+ (1500, "B+"), (1000, "B"), (500, "B-")
137
+ ]
138
+
139
+ for threshold, grade in grades:
140
+ if total_score >= threshold:
141
+ return grade, total_score
142
+
143
+ return "B-", total_score
144
+
145
+ # get_card ํ•จ์ˆ˜ ๋‚ด์˜ hardware_info ๋ถ€๋ถ„์„ ๋‹ค์Œ์œผ๋กœ ๊ต์ฒด:
146
+ def get_rating_info(item: dict, index: int) -> str:
147
+ """ํ‰๊ฐ€ ์ •๋ณด HTML ์ƒ์„ฑ"""
148
+ created = item.get('createdAt', '').split('T')[0]
149
+ likes = int(str(item.get('likes', '0')).replace(',', ''))
150
+
151
+ # AI Rising Rate ๊ณ„์‚ฐ
152
+ stars = calculate_rising_rate(created, index + 1)
153
+ star_html = "โ˜…" * stars + "โ˜†" * (5 - stars) # ์ฑ„์›Œ์ง„ ๋ณ„๊ณผ ๋นˆ ๋ณ„ ์กฐํ•ฉ
154
+
155
+ # AI Popularity Score ๊ณ„์‚ฐ
156
+ grade, score = get_popularity_grade(likes, stars)
157
+
158
+ # ๋“ฑ๊ธ‰๋ณ„ ์ƒ‰์ƒ ์„ค์ •
159
+ grade_colors = {
160
+ 'AAA': '#FFD700', 'AA': '#FFA500', 'A': '#FF4500',
161
+ 'BBB': '#4169E1', 'BB': '#1E90FF', 'B': '#00BFFF'
162
+ }
163
+ grade_base = grade.rstrip('+-')
164
+ grade_color = grade_colors.get(grade_base, '#666666')
165
+
166
+ return f"""
167
+ <div style='
168
+ margin-top: 15px;
169
+ padding: 15px;
170
+ background: rgba(255,255,255,0.4);
171
+ border-radius: 10px;
172
+ font-size: 0.9em;
173
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);'>
174
+ <div style='
175
+ display: grid;
176
+ grid-template-columns: repeat(2, 1fr);
177
+ gap: 15px;'>
178
+ <div style='
179
+ color: #333;
180
+ display: flex;
181
+ flex-direction: column;
182
+ gap: 5px;'>
183
+ <span style='font-weight: bold;'>AI Rising Rate:</span>
184
+ <span style='
185
+ color: #FF8C00;
186
+ font-size: 1.4em;
187
+ letter-spacing: 2px;
188
+ text-shadow: 1px 1px 2px rgba(0,0,0,0.1);'>{star_html}</span>
189
+ </div>
190
+ <div style='
191
+ color: #333;
192
+ display: flex;
193
+ flex-direction: column;
194
+ gap: 5px;'>
195
+ <span style='font-weight: bold;'>AI Popularity Score:</span>
196
+ <span style='
197
+ font-size: 1.2em;
198
+ font-weight: bold;
199
+ color: {grade_color};
200
+ text-shadow: 1px 1px 2px rgba(0,0,0,0.1);'>{grade} ({score:,})</span>
201
+ </div>
202
+ </div>
203
+ </div>
204
+ """
205
+
206
  def get_hardware_info(item: dict) -> tuple:
207
  """ํ•˜๋“œ์›จ์–ด ์ •๋ณด ์ถ”์ถœ"""
208
  try:
 
238
  except Exception as e:
239
  print(f"Error parsing hardware info: {str(e)}")
240
  return 'Standard', 'None', 'N/A'
241
+
242
  def get_card(item: dict, index: int, card_type: str = "space") -> str:
243
  """ํ†ตํ•ฉ ์นด๋“œ HTML ์ƒ์„ฑ"""
244
  item_id = item.get('id', '')
 
259
  pipeline_tag = item.get('pipeline_tag', '')
260
  license = item.get('license', '')
261
  sdk = item.get('sdk', 'N/A')
262
+
263
+ # AI Rating ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
264
+ rating_info = get_rating_info(item, index)
265
+
 
 
 
 
 
266
 
267
  # ์นด๋“œ ํƒ€์ž…๋ณ„ ๊ทธ๋ผ๋ฐ์ด์…˜ ์„ค์ •
268
  if card_type == "space":
 
479
 
480
  try:
481
  progress(0, desc="Fetching spaces data...")
 
482
  params = {
483
  'full': 'true',
484
+ 'limit': 10
 
 
485
  }
486
+ response = requests.get(url, params=params)
 
 
 
 
487
  response.raise_for_status()
488
  spaces = response.json()
489
 
 
 
 
490
  # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
491
  top_spaces = spaces[:10]
 
 
492
 
493
  progress(0.1, desc="Creating gallery...")
494
  html_content = """