Omnibus commited on
Commit
8830ea3
·
verified ·
1 Parent(s): e818063

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  #from __future__ import annotations
2
  from selenium import webdriver
3
-
4
  import gradio as gr
5
  import uuid
6
  import re
@@ -13,7 +13,26 @@ from selenium.webdriver.common.by import By
13
 
14
  driver_type = 'chromedriver'
15
  driver=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def run_script(url: str, height: int, width: int):
 
17
  uid=uuid.uuid4()
18
  is_url=True
19
  if is_url:
@@ -38,8 +57,10 @@ def run_script(url: str, height: int, width: int):
38
  obj = driver.find_element(By.CLASS_NAME, "main")
39
  messages = driver.find_elements(By.CLASS_NAME, "message")
40
  print (len(messages))
41
- for mes in messages:
42
- print (messages.text)
 
 
43
  #obj = driver.find_element(By.ID, "app-container")
44
  #obj = driver.find_element(By.ID, "conversation-feed")
45
  #obj = driver.find_element_by_id("in_html")
@@ -63,15 +84,15 @@ def run_script(url: str, height: int, width: int):
63
  screenshot = obj.screenshot(f'{uid}-tmp.png')
64
  #screenshot = obj.get_screenshot_as_png()
65
  except WebDriverException as e:
66
- return [Image.new('RGB', (1, 1)), f'<center>{e}']
67
  finally:
68
  if driver:
69
  driver.quit()
70
 
71
  #return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
72
- return [Image.open(f'{uid}-tmp.png'), '<center>operation success.']
73
  else:
74
- return [None, '<center>Please enter a valid URL of a website/host.']
75
 
76
  with gr.Blocks() as app:
77
 
@@ -85,6 +106,8 @@ with gr.Blocks() as app:
85
  height=gr.Number(label="Height", value=4096)
86
  width=gr.Number(label="Width",value=800)
87
  message=gr.HTML('<center>Enter URL')
88
- outim = gr.Image()
89
- btn.click(run_script,[inp,height,width],[outim,message])
 
 
90
  app.launch()
 
1
  #from __future__ import annotations
2
  from selenium import webdriver
3
+ from PIL import Image
4
  import gradio as gr
5
  import uuid
6
  import re
 
13
 
14
  driver_type = 'chromedriver'
15
  driver=False
16
+
17
+ def get_concat_h_cut(im1, im2):
18
+ dst = Image.new('RGB', (im1.width + im2.width,
19
+ min(im1.height, im2.height)))
20
+ dst.paste(im1, (0, 0))
21
+ dst.paste(im2, (im1.width, 0))
22
+ return dst
23
+
24
+
25
+ def get_concat_v_cut(im1, im2):
26
+ dst = Image.new(
27
+ 'RGB', (min(im1.width, im2.width), im1.height + im2.height))
28
+ dst.paste(im1, (0, 0))
29
+ dst.paste(im2, (0, im1.height))
30
+ return dst
31
+
32
+
33
+
34
  def run_script(url: str, height: int, width: int):
35
+ mes_box=[]
36
  uid=uuid.uuid4()
37
  is_url=True
38
  if is_url:
 
57
  obj = driver.find_element(By.CLASS_NAME, "main")
58
  messages = driver.find_elements(By.CLASS_NAME, "message")
59
  print (len(messages))
60
+ for i,mes in enumerate(messages):
61
+ print (mes.text)
62
+ mes_shot = obj.screenshot(f'{i}{uid}-tmp.png')
63
+ mes_box.append(mes_shot)
64
  #obj = driver.find_element(By.ID, "app-container")
65
  #obj = driver.find_element(By.ID, "conversation-feed")
66
  #obj = driver.find_element_by_id("in_html")
 
84
  screenshot = obj.screenshot(f'{uid}-tmp.png')
85
  #screenshot = obj.get_screenshot_as_png()
86
  except WebDriverException as e:
87
+ return [Image.new('RGB', (1, 1)), f'<center>{e}',mes_box]
88
  finally:
89
  if driver:
90
  driver.quit()
91
 
92
  #return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
93
+ return [Image.open(f'{uid}-tmp.png'), '<center>operation success.',mes_box]
94
  else:
95
+ return [None, '<center>Please enter a valid URL of a website/host.',mes_box]
96
 
97
  with gr.Blocks() as app:
98
 
 
106
  height=gr.Number(label="Height", value=4096)
107
  width=gr.Number(label="Width",value=800)
108
  message=gr.HTML('<center>Enter URL')
109
+ with gr.Row():
110
+ outim = gr.Image()
111
+ outgal=gr.Gallery()
112
+ btn.click(run_script,[inp,height,width],[outim,message,outgal])
113
  app.launch()