Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
-
from html2image import Html2Image
|
| 3 |
import gradio as gr
|
| 4 |
print(os.environ)
|
| 5 |
-
hti = Html2Image()
|
| 6 |
-
def txt2img(inp):
|
| 7 |
-
html = f"""
|
| 8 |
-
<div class='im_div'>
|
| 9 |
-
{inp}
|
| 10 |
-
<div>
|
| 11 |
-
"""
|
| 12 |
-
css = ".im_div {background: red;}"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
with gr.Blocks() as app:
|
|
@@ -22,5 +21,5 @@ with gr.Blocks() as app:
|
|
| 22 |
btn=gr.Button()
|
| 23 |
outhtml=gr.HTML()
|
| 24 |
outp=gr.Image()
|
| 25 |
-
btn.click(
|
| 26 |
app.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
+
#from html2image import Html2Image
|
| 3 |
import gradio as gr
|
| 4 |
print(os.environ)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
import asyncio
|
| 7 |
+
from playwright.async_api import async_playwright
|
| 8 |
+
|
| 9 |
+
async def main(inp):
|
| 10 |
+
async with async_playwright() as p:
|
| 11 |
+
browser = await p.chromium.launch()
|
| 12 |
+
page = await browser.new_page()
|
| 13 |
+
await page.goto('https://www.bbc.co.uk/news/business-63709754')
|
| 14 |
+
await page.locator('.ssrcss-hmf8ql-BoldText').screenshot(path='element.png')
|
| 15 |
+
await browser.close()
|
| 16 |
+
return ("done",'element.png')
|
| 17 |
|
| 18 |
|
| 19 |
with gr.Blocks() as app:
|
|
|
|
| 21 |
btn=gr.Button()
|
| 22 |
outhtml=gr.HTML()
|
| 23 |
outp=gr.Image()
|
| 24 |
+
btn.click(main,inp,[outhtml,outp])
|
| 25 |
app.launch()
|