Omnibus commited on
Commit
7582481
·
verified ·
1 Parent(s): 8d029c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -62,26 +62,44 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
62
 
63
  obj = driver.find_element(By.CLASS_NAME, "main")
64
  messages = driver.find_elements(By.CLASS_NAME, "message")
65
- print (len(messages))
66
- mes_blocks=len(messages)%2
67
- for ea in check_b:
 
68
  try:
69
  ea = int(ea)
70
  ea = (ea*2)-2
71
  print (ea)
72
- messages[ea].screenshot(f'{ea}-{uid}-tmp.png')
73
- messages[ea+1].screenshot(f'{ea+1}-{uid}-tmp.png')
74
- if check_h:
75
- head_paste = get_concat_v_cut(f'head-{uid}-tmp.png',f'{ea}-{uid}-tmp.png')
76
- head_paste.save(f'im1-{uid}-tmp.png')
77
- print(head_paste)
78
- out_box.append(get_concat_v_cut(f'im1-{uid}-tmp.png',f'{ea+1}-{uid}-tmp.png'))
79
- if not check_h:
80
- out_box.append(get_concat_v_cut(f'{ea}-{uid}-tmp.png',f'{ea+1}-{uid}-tmp.png'))
81
  print(f'out_box:: {out_box}')
82
  #mes_box.clear()
83
  except Exception:
84
  mes="<center>Some blocks returned an error"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  '''
86
  for i,mes in enumerate(messages):
87
  print (mes.text)
@@ -116,15 +134,15 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
116
  screenshot = obj.screenshot(f'{uid}-tmp.png')
117
  #screenshot = obj.get_screenshot_as_png()
118
  except WebDriverException as e:
119
- return Image.new('RGB', (1, 1)), f'<center>{e}',out_box
120
  finally:
121
  if driver:
122
  driver.quit()
123
 
124
  #return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
125
- return Image.open(f'{uid}-tmp.png'), mes,out_box
126
  else:
127
- return None, '<center>Please enter a valid URL of a website/host.',out_box
128
 
129
  with gr.Blocks() as app:
130
 
@@ -142,8 +160,9 @@ with gr.Blocks() as app:
142
  message=gr.HTML('<center>Enter URL')
143
  with gr.Row():
144
  with gr.Column():
 
145
  outgal=gr.Gallery()
146
  outim = gr.Image()
147
 
148
- btn.click(run_script,[inp,height,width,check_b,check_h],[outim,message,outgal])
149
  app.launch()
 
62
 
63
  obj = driver.find_element(By.CLASS_NAME, "main")
64
  messages = driver.find_elements(By.CLASS_NAME, "message")
65
+ #print (len(messages))
66
+ #mes_blocks=len(messages)%2
67
+
68
+ for i,ea in enumerate(check_b):
69
  try:
70
  ea = int(ea)
71
  ea = (ea*2)-2
72
  print (ea)
73
+ messages[ea].screenshot(f'{i}-{uid}-tmp.png')
74
+ messages[ea+1].screenshot(f'{i+1}-{uid}-tmp.png')
75
+ im_roll = get_concat_v_cut(f'{i}-{uid}-tmp.png',f'{i+1}-{uid}-tmp.png')
76
+ im_roll.save(f'comb{i}-{uid}-tmp.png')
77
+ out_box.append(f'comb{i}-{uid}-tmp.png')
78
+
79
+
 
 
80
  print(f'out_box:: {out_box}')
81
  #mes_box.clear()
82
  except Exception:
83
  mes="<center>Some blocks returned an error"
84
+ if out_box:
85
+ for i in range(len(out_box)-2):
86
+ if i == 0:
87
+ im_roll = get_concat_v_cut(f'{out_box[i]}',f'{out_box[i+1]}')
88
+ im_roll.save(f'comb-{uid}-tmp.png')
89
+ else:
90
+ im_roll = get_concat_v_cut(f'comb-{uid}-tmp.png',f'{out_box[i+1]}')
91
+ im_roll.save(f'comb-{uid}-tmp.png')
92
+
93
+
94
+ if check_h:
95
+ head_paste = get_concat_v_cut(f'head-{uid}-tmp.png',f'comb-{uid}-tmp.png')
96
+ head_paste.save(f'comb-{uid}-tmp.png')
97
+ out = f'comb-{uid}-tmp.png'
98
+
99
+
100
+
101
+
102
+
103
  '''
104
  for i,mes in enumerate(messages):
105
  print (mes.text)
 
134
  screenshot = obj.screenshot(f'{uid}-tmp.png')
135
  #screenshot = obj.get_screenshot_as_png()
136
  except WebDriverException as e:
137
+ return Image.new('RGB', (1, 1)), f'<center>{e}',out_box,out
138
  finally:
139
  if driver:
140
  driver.quit()
141
 
142
  #return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
143
+ return Image.open(f'{uid}-tmp.png'), mes,out_box,out
144
  else:
145
+ return None, '<center>Please enter a valid URL of a website/host.',out_box,out
146
 
147
  with gr.Blocks() as app:
148
 
 
160
  message=gr.HTML('<center>Enter URL')
161
  with gr.Row():
162
  with gr.Column():
163
+ out=gr.Image()
164
  outgal=gr.Gallery()
165
  outim = gr.Image()
166
 
167
+ btn.click(run_script,[inp,height,width,check_b,check_h],[outim,message,outgal,out])
168
  app.launch()