Omnibus commited on
Commit
550d985
1 Parent(s): 3a0e4e5

Create app.py

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