Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,9 @@ import os
|
|
4 |
import requests
|
5 |
from typing import List, Dict, Union
|
6 |
import traceback
|
7 |
-
|
8 |
-
from selenium import webdriver
|
9 |
-
from selenium.common.exceptions import WebDriverException
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
12 |
|
13 |
-
from playwright.sync_api import sync_playwright
|
14 |
-
from selenium.webdriver.chrome.options import Options
|
15 |
|
16 |
|
17 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
@@ -98,37 +93,30 @@ def on_select(space):
|
|
98 |
try:
|
99 |
summary = summarize_space(space)
|
100 |
app_content = get_app_py_content(space['id'])
|
101 |
-
|
102 |
info = f"์ ํ๋ Space: {space['name']} (ID: {space['id']})\n"
|
103 |
info += f"Author: {space['author']}\n"
|
104 |
info += f"Likes: {space['likes']}\n"
|
105 |
info += f"URL: {space['url']}\n\n"
|
106 |
info += f"์์ฝ:\n{summary}"
|
107 |
-
return info, app_content,
|
108 |
except Exception as e:
|
109 |
print(f"Error in on_select: {str(e)}")
|
110 |
print(traceback.format_exc())
|
111 |
-
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", Image.new('RGB', (
|
112 |
|
113 |
-
def
|
114 |
try:
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
driver = webdriver.Chrome(options=chrome_options)
|
123 |
-
|
124 |
-
driver.get(url)
|
125 |
-
screenshot = driver.get_screenshot_as_png()
|
126 |
-
driver.quit()
|
127 |
-
|
128 |
-
return Image.open(BytesIO(screenshot))
|
129 |
except Exception as e:
|
130 |
-
print(f"
|
131 |
-
return Image.new('RGB', (
|
132 |
|
133 |
def create_ui():
|
134 |
try:
|
@@ -158,14 +146,14 @@ def create_ui():
|
|
158 |
|
159 |
with gr.Column(scale=1):
|
160 |
info_output = gr.Textbox(label="Space ์ ๋ณด ๋ฐ ์์ฝ", lines=20)
|
161 |
-
|
162 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
163 |
|
164 |
for _, button, space in space_rows:
|
165 |
button.click(
|
166 |
lambda s=space: on_select(s),
|
167 |
inputs=[],
|
168 |
-
outputs=[info_output, app_py_content,
|
169 |
)
|
170 |
|
171 |
|
|
|
4 |
import requests
|
5 |
from typing import List, Dict, Union
|
6 |
import traceback
|
|
|
|
|
|
|
7 |
from PIL import Image
|
8 |
from io import BytesIO
|
9 |
|
|
|
|
|
10 |
|
11 |
|
12 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
93 |
try:
|
94 |
summary = summarize_space(space)
|
95 |
app_content = get_app_py_content(space['id'])
|
96 |
+
thumbnail = get_space_thumbnail(space['id'])
|
97 |
info = f"์ ํ๋ Space: {space['name']} (ID: {space['id']})\n"
|
98 |
info += f"Author: {space['author']}\n"
|
99 |
info += f"Likes: {space['likes']}\n"
|
100 |
info += f"URL: {space['url']}\n\n"
|
101 |
info += f"์์ฝ:\n{summary}"
|
102 |
+
return info, app_content, thumbnail
|
103 |
except Exception as e:
|
104 |
print(f"Error in on_select: {str(e)}")
|
105 |
print(traceback.format_exc())
|
106 |
+
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", Image.new('RGB', (400, 300), color='lightgray')
|
107 |
|
108 |
+
def get_space_thumbnail(space_id: str) -> Image.Image:
|
109 |
try:
|
110 |
+
thumbnail_url = f"https://huggingface.co/spaces/{space_id}/resolve/main/thumbnail.png"
|
111 |
+
response = requests.get(thumbnail_url)
|
112 |
+
if response.status_code == 200:
|
113 |
+
return Image.open(BytesIO(response.content))
|
114 |
+
else:
|
115 |
+
print(f"Thumbnail not found for space: {space_id}")
|
116 |
+
return Image.new('RGB', (400, 300), color='lightgray')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
except Exception as e:
|
118 |
+
print(f"Error fetching thumbnail: {str(e)}")
|
119 |
+
return Image.new('RGB', (400, 300), color='lightgray')
|
120 |
|
121 |
def create_ui():
|
122 |
try:
|
|
|
146 |
|
147 |
with gr.Column(scale=1):
|
148 |
info_output = gr.Textbox(label="Space ์ ๋ณด ๋ฐ ์์ฝ", lines=20)
|
149 |
+
thumbnail_output = gr.Image(type="pil", label="Space ์ธ๋ค์ผ", height=300, width=400)
|
150 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
151 |
|
152 |
for _, button, space in space_rows:
|
153 |
button.click(
|
154 |
lambda s=space: on_select(s),
|
155 |
inputs=[],
|
156 |
+
outputs=[info_output, app_py_content, thumbnail_output]
|
157 |
)
|
158 |
|
159 |
|