Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,31 +13,22 @@ class HtmlInput(BaseModel):
|
|
13 |
message: str
|
14 |
|
15 |
|
16 |
-
|
17 |
async def convert_html_to_image(html, output_file, width=612, height=800, device_scale_factor=2):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
'--no-sandbox',
|
22 |
-
'
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
)
|
34 |
-
page = await browser.newPage()
|
35 |
-
await page.setViewport({'width': width, 'height': height, 'deviceScaleFactor': device_scale_factor})
|
36 |
-
await page.setContent(html)
|
37 |
-
# Capture only the viewport without extra white space
|
38 |
-
await page.screenshot({'path': output_file})
|
39 |
-
await browser.close()
|
40 |
-
return output_file # Return the path of the captured image
|
41 |
|
42 |
# Function to tilt the content randomly
|
43 |
def tilt_content(html_content):
|
|
|
13 |
message: str
|
14 |
|
15 |
|
|
|
16 |
async def convert_html_to_image(html, output_file, width=612, height=800, device_scale_factor=2):
|
17 |
+
try:
|
18 |
+
browser = await launch({
|
19 |
+
'headless': True,
|
20 |
+
'args': ['--no-sandbox', '--disable-setuid-sandbox'],
|
21 |
+
'timeout': 60000 # Increase timeout if needed
|
22 |
+
})
|
23 |
+
page = await browser.newPage()
|
24 |
+
await page.setViewport({'width': width, 'height': height, 'deviceScaleFactor': device_scale_factor})
|
25 |
+
await page.setContent(html)
|
26 |
+
await page.screenshot({'path': output_file})
|
27 |
+
await browser.close()
|
28 |
+
return output_file # Return the path of the captured image
|
29 |
+
except Exception as e:
|
30 |
+
print(f"Error in convert_html_to_image: {e}")
|
31 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Function to tilt the content randomly
|
34 |
def tilt_content(html_content):
|