Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,32 @@ import requests
|
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
USERNAME = "openfree"
|
7 |
|
@@ -254,15 +280,55 @@ def get_vercel_deployments():
|
|
254 |
return []
|
255 |
|
256 |
def get_vercel_card(deployment, index):
|
257 |
-
"""
|
258 |
raw_url = deployment.get('url', '')
|
259 |
|
260 |
-
# URL ์ฒ๋ฆฌ
|
261 |
if raw_url.startswith('http'):
|
262 |
-
url = raw_url
|
263 |
else:
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
# Hugging Face ์คํ์ด์ค URL์ธ ๊ฒฝ์ฐ ์ง์ ์ฌ์ฉ
|
268 |
if 'huggingface.co' in url:
|
@@ -685,4 +751,7 @@ with demo:
|
|
685 |
html_output = gr.HTML(value=get_user_spaces()) # ์ด๊ธฐ ๋ก๋ ์ ์ง์ ํจ์ ํธ์ถ
|
686 |
|
687 |
if __name__ == "__main__":
|
|
|
|
|
|
|
688 |
demo.launch()
|
|
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
import random
|
5 |
+
from selenium import webdriver
|
6 |
+
from selenium.common.exceptions import WebDriverException
|
7 |
+
from PIL import Image
|
8 |
+
from io import BytesIO
|
9 |
+
|
10 |
+
def take_screenshot(url):
|
11 |
+
"""์น์ฌ์ดํธ ์คํฌ๋ฆฐ์ท ์ดฌ์ ํจ์"""
|
12 |
+
options = webdriver.ChromeOptions()
|
13 |
+
options.add_argument('--headless')
|
14 |
+
options.add_argument('--no-sandbox')
|
15 |
+
options.add_argument('--disable-dev-shm-usage')
|
16 |
+
|
17 |
+
try:
|
18 |
+
driver = webdriver.Chrome(options=options)
|
19 |
+
driver.set_window_size(1080, 720) # ์คํฌ๋ฆฐ์ท ํฌ๊ธฐ ์ค์
|
20 |
+
driver.get(url)
|
21 |
+
driver.implicitly_wait(10)
|
22 |
+
screenshot = driver.get_screenshot_as_png()
|
23 |
+
return Image.open(BytesIO(screenshot))
|
24 |
+
except WebDriverException as e:
|
25 |
+
print(f"์คํฌ๋ฆฐ์ท ์ดฌ์ ์คํจ: {str(e)}")
|
26 |
+
return Image.new('RGB', (1, 1)) # ์ค๋ฅ ์ ๋น ์ด๋ฏธ์ง ๋ฐํ
|
27 |
+
finally:
|
28 |
+
if driver:
|
29 |
+
driver.quit()
|
30 |
+
|
31 |
|
32 |
USERNAME = "openfree"
|
33 |
|
|
|
280 |
return []
|
281 |
|
282 |
def get_vercel_card(deployment, index):
|
283 |
+
"""Vercel ๋ฐฐํฌ ์นด๋ HTML ์์ฑ ํจ์"""
|
284 |
raw_url = deployment.get('url', '')
|
285 |
|
286 |
+
# URL ์ฒ๋ฆฌ
|
287 |
if raw_url.startswith('http'):
|
288 |
+
url = raw_url
|
289 |
else:
|
290 |
+
url = f"https://{raw_url}"
|
291 |
+
|
292 |
+
name = deployment.get('name', '์ด๋ฆ ์๋ ํ๋ก์ ํธ')
|
293 |
+
created = format_timestamp(deployment.get('created'))
|
294 |
+
state = deployment.get('state', 'N/A')
|
295 |
+
|
296 |
+
# ์นด๋ ID ์์ฑ
|
297 |
+
card_id = f"vercel-card-{url.replace('.', '-').replace('/', '-')}"
|
298 |
+
|
299 |
+
|
300 |
+
# ์คํฌ๋ฆฐ์ท ์ด๋ฏธ์ง ๊ฐ์ ธ์ค๊ธฐ
|
301 |
+
try:
|
302 |
+
screenshot = take_screenshot(url)
|
303 |
+
screenshot_html = f"""
|
304 |
+
<div style="width: 100%; height: 200px; overflow: hidden; border-radius: 10px; margin-bottom: 15px;">
|
305 |
+
<img src="data:image/png;base64,{screenshot}"
|
306 |
+
style="width: 100%; height: 100%; object-fit: cover;"
|
307 |
+
alt="{name} ์คํฌ๋ฆฐ์ท"/>
|
308 |
+
</div>
|
309 |
+
"""
|
310 |
+
except Exception as e:
|
311 |
+
print(f"์คํฌ๋ฆฐ์ท ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}")
|
312 |
+
screenshot_html = "" # ์ค๋ฅ ์ ์คํฌ๋ฆฐ์ท ์์ญ ์๋ต
|
313 |
+
|
314 |
+
# ๋๋จธ์ง ์นด๋ ์คํ์ผ๋ง ์ฝ๋๋ ๊ธฐ์กด๊ณผ ๋์ผ...
|
315 |
+
return f"""
|
316 |
+
<div id="{card_id}" class="vercel-card"
|
317 |
+
style='border: none;
|
318 |
+
padding: 25px;
|
319 |
+
margin: 15px;
|
320 |
+
border-radius: 20px;
|
321 |
+
background-color: {get_pastel_color(index)};
|
322 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.1);'>
|
323 |
+
{screenshot_html}
|
324 |
+
<h3>{name}</h3>
|
325 |
+
<div style='margin: 15px 0;'>
|
326 |
+
<p>์ํ: {state}</p>
|
327 |
+
<p>์์ฑ์ผ: {created}</p>
|
328 |
+
<p>URL: <a href="{url}" target="_blank">{url}</a></p>
|
329 |
+
</div>
|
330 |
+
</div>
|
331 |
+
"""
|
332 |
|
333 |
# Hugging Face ์คํ์ด์ค URL์ธ ๊ฒฝ์ฐ ์ง์ ์ฌ์ฉ
|
334 |
if 'huggingface.co' in url:
|
|
|
751 |
html_output = gr.HTML(value=get_user_spaces()) # ์ด๊ธฐ ๋ก๋ ์ ์ง์ ํจ์ ํธ์ถ
|
752 |
|
753 |
if __name__ == "__main__":
|
754 |
+
demo = gr.Blocks()
|
755 |
+
with demo:
|
756 |
+
gr.HTML(value=get_user_spaces())
|
757 |
demo.launch()
|