| | import gradio as gr |
| | import tempfile |
| | from playwright.sync_api import sync_playwright |
| |
|
| | |
| | |
| | |
| | def html_to_png(html_path): |
| | output_png = tempfile.NamedTemporaryFile( |
| | delete=False, suffix=".png" |
| | ).name |
| |
|
| | with sync_playwright() as p: |
| | browser = p.chromium.launch( |
| | args=["--no-sandbox", "--disable-dev-shm-usage"] |
| | ) |
| | page = browser.new_page( |
| | viewport={"width": 2000, "height": 1414} |
| | ) |
| | page.goto(f"file://{html_path}", wait_until="networkidle") |
| | page.screenshot(path=output_png) |
| | browser.close() |
| |
|
| | return output_png |
| |
|
| | |
| | |
| | |
| | demo = gr.Interface( |
| | fn=html_to_png, |
| | inputs=gr.File(type="filepath", label="HTML Input"), |
| | outputs=gr.File(type="filepath", label="PNG Output"), |
| | title="HTML β PNG Certificate API", |
| | description="Production-ready HTML to PNG API" |
| | ) |
| |
|
| | demo.launch(ssr_mode=False) |
| |
|