Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
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 |
-
|
147 |
-
|
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 |
-
|
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 = """
|