Soham0708 commited on
Commit
4591f60
·
verified ·
1 Parent(s): b8e2339

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
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
- browser = await launch(
19
- headless=True,
20
- args=[
21
- '--no-sandbox',
22
- '--disable-setuid-sandbox',
23
- '--disable-gpu',
24
- '--disable-dev-shm-usage', # Try to disable /dev/shm usage
25
- '--disable-software-rasterizer',
26
- '--disable-accelerated-2d-canvas',
27
- '--disable-infobars',
28
- '--disable-extensions',
29
- '--disable-features=NetworkService',
30
- '--disable-features=VizDisplayCompositor',
31
- '--window-size=612,800'
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):