Spaces:
Runtime error
Runtime error
File size: 3,099 Bytes
0194520 877909a 3b17cd9 33b91dd c85554c 5fb1469 60474ac 3b17cd9 2084d9f 355ae5e 04e8258 3922bdb 407f1a0 3b17cd9 48d2a87 355ae5e 3b17cd9 02a204c 407f1a0 3b17cd9 3009007 c85554c ff4dc67 76daedd 5fb1469 3009007 5fb1469 76daedd ff4dc67 b3acf20 407f1a0 10ab262 907b5ba 3b17cd9 e38117a de3f5df 3b17cd9 10ab262 9b1d63a 3b17cd9 7c8ed89 3b17cd9 355ae5e 48d2a87 bd6144a 48d2a87 3b17cd9 355ae5e 3b17cd9 9ad07bf 9b1d63a 7c8ed89 355ae5e 3b17cd9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | from __future__ import annotations
from selenium import webdriver
#from typing import Iterable
import gradio as gr
import re
from PIL import Image
from io import BytesIO
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium_webdriver import WebElement
driver_type = 'chromedriver'
driver=False
def run_script(html: str, style: str):
html = html.replace("\n","<br>")
#regex = r"^(https?://)"
#is_url = re.search(regex, text)
is_url=True
if is_url:
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
try:
url = f"https://omnibus-txt2img-static.static.hf.space/index.html?format={style}&txt={html}"
driver = webdriver.Chrome(options=options)
driver.get(url)
#html=driver.page_source
driver.implicitly_wait(30)
driver.set_window_size(1920, 1080)
obj = driver.find_element(By.NAME, "in_card")
#obj = driver.find_element_by_id("in_html")
######################
#inp = driver.find_element("id","input")
'''
find_element(By.ID, "id")
find_element(By.NAME, "name")
find_element(By.XPATH, "xpath")
find_element(By.LINK_TEXT, "link text")
find_element(By.PARTIAL_LINK_TEXT, "partial link text")
find_element(By.TAG_NAME, "tag name")
find_element(By.CLASS_NAME, "class name")
find_element(By.CSS_SELECTOR, "css selector")
'''
#inp.send_keys("test")
######################
cookie_jar = []
#cookie_jar.append(driver.get_cookies())
#print(cookie_jar)
screenshot = obj.screenshot('tmp.png')
#screenshot = obj.get_screenshot_as_png()
except WebDriverException as e:
return [Image.new('RGB', (1, 1)), e, None,None]
finally:
if driver:
driver.quit()
#return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
return [Image.open('tmp.png'), 'operation success.',url,html]
else:
return [None, 'Please enter a valid URL of a website/host.',None,None]
html="""<h1>This is the title</h1>
<pre> This is some information
bla bla
• a bullet
• or two
</pre>"""
sty="""background:cornflowerblue;height:300;width:500;"""
with gr.Blocks() as app:
with gr.Row():
inp = gr.Textbox(lines=8,max_lines=50,value=html)
style = gr.Textbox(lines=8,max_lines=50,value=sty)
btn= gr.Button()
with gr.Row():
with gr.Column():
outim = gr.Image()
with gr.Column():
outp = gr.Textbox()
cook = gr.Textbox()
html=gr.Textbox()
btn.click(run_script,[inp,style],[outim,outp,cook,html])
app.launch() |