Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,8 @@ from selenium.common.exceptions import WebDriverException
|
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
12 |
|
|
|
|
|
13 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
14 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
15 |
|
@@ -102,30 +104,19 @@ def on_select(space):
|
|
102 |
print(f"Error in on_select: {str(e)}")
|
103 |
print(traceback.format_exc())
|
104 |
return f"오류가 발생했습니다: {str(e)}", "", Image.new('RGB', (1, 1))
|
105 |
-
|
106 |
-
def take_screenshot(url):
|
107 |
-
options = webdriver.ChromeOptions()
|
108 |
-
options.add_argument('--headless')
|
109 |
-
options.add_argument('--no-sandbox')
|
110 |
-
options.add_argument('--disable-dev-shm-usage')
|
111 |
|
112 |
-
|
113 |
try:
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
119 |
return Image.open(BytesIO(screenshot))
|
120 |
-
except WebDriverException as e:
|
121 |
-
print(f"WebDriver error: {str(e)}")
|
122 |
-
return Image.new('RGB', (1, 1))
|
123 |
except Exception as e:
|
124 |
-
print(f"
|
125 |
return Image.new('RGB', (1, 1))
|
126 |
-
finally:
|
127 |
-
if wd:
|
128 |
-
wd.quit()
|
129 |
|
130 |
|
131 |
def create_ui():
|
|
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
12 |
|
13 |
+
from playwright.sync_api import sync_playwright
|
14 |
+
|
15 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
16 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
17 |
|
|
|
104 |
print(f"Error in on_select: {str(e)}")
|
105 |
print(traceback.format_exc())
|
106 |
return f"오류가 발생했습니다: {str(e)}", "", Image.new('RGB', (1, 1))
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
def take_screenshot(url):
|
109 |
try:
|
110 |
+
with sync_playwright() as p:
|
111 |
+
browser = p.chromium.launch()
|
112 |
+
page = browser.new_page()
|
113 |
+
page.goto(url)
|
114 |
+
screenshot = page.screenshot()
|
115 |
+
browser.close()
|
116 |
return Image.open(BytesIO(screenshot))
|
|
|
|
|
|
|
117 |
except Exception as e:
|
118 |
+
print(f"Screenshot error: {str(e)}")
|
119 |
return Image.new('RGB', (1, 1))
|
|
|
|
|
|
|
120 |
|
121 |
|
122 |
def create_ui():
|