openfree commited on
Commit
f79dac7
โ€ข
1 Parent(s): 8dfed1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -5
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
- """Generate HTML card for a Vercel deployment with like button"""
258
  raw_url = deployment.get('url', '')
259
 
260
- # URL ์ฒ˜๋ฆฌ ๋กœ์ง ์ˆ˜์ •
261
  if raw_url.startswith('http'):
262
- url = raw_url # ์ „์ฒด URL์ด ์ œ๊ณต๋œ ๊ฒฝ์šฐ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ
263
  else:
264
- project_name = raw_url[:6] if len(raw_url) >= 6 else raw_url
265
- url = f"{project_name}.vercel.app"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()