Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -121,6 +121,10 @@ def run_script(url: str, height: int, width: int, check_b,check_h,wait_time):
|
|
121 |
print(html)
|
122 |
driver.implicitly_wait(int(wait_time*30))
|
123 |
driver.set_window_size(int(width), int(height))
|
|
|
|
|
|
|
|
|
124 |
|
125 |
main_head = driver.find_element(By.CLASS_NAME, "main-content-header")
|
126 |
head_shot = main_head.screenshot(f'head-{uid}-tmp.png')
|
@@ -139,15 +143,14 @@ def run_script(url: str, height: int, width: int, check_b,check_h,wait_time):
|
|
139 |
except Exception:
|
140 |
mes="<center>Some blocks returned an error"
|
141 |
|
142 |
-
screenshot = driver.save_screenshot(f'{uid}-tmp.png')
|
143 |
except WebDriverException as e:
|
144 |
return Image.new('RGB', (1, 1)), f'<center>Please enter a valid URL of a website/host.',out_box,out
|
145 |
finally:
|
146 |
if driver:
|
147 |
driver.quit()
|
148 |
-
|
149 |
else:
|
150 |
-
|
151 |
def load_frame(inp):
|
152 |
html_mod=f"""
|
153 |
<div id="my_game" style="height:600px;width:100%">
|
@@ -166,9 +169,10 @@ with gr.Blocks() as app:
|
|
166 |
with gr.Row():
|
167 |
with gr.Column():
|
168 |
inp = gr.Textbox(label="URL (must be Public)",lines=1)
|
|
|
169 |
with gr.Row():
|
170 |
-
wait_t=gr.Slider(1, 10000, value=2000, label="Wait time", info="Wait for page to load. More data = Longer wait")
|
171 |
btn= gr.Button("Snapshot")
|
|
|
172 |
|
173 |
with gr.Column():
|
174 |
check_h=gr.Checkbox(label="Show Header", value=True)
|
@@ -184,5 +188,6 @@ with gr.Blocks() as app:
|
|
184 |
outim = gr.Image()
|
185 |
prev=gr.HTML()
|
186 |
#load_btn.click(load_frame,inp,prev)
|
187 |
-
btn.click(run_script,[inp,height,width,check_b,check_h,wait_t],[outim,message,outgal,out])
|
|
|
188 |
app.queue(default_concurrency_limit=5).launch()
|
|
|
121 |
print(html)
|
122 |
driver.implicitly_wait(int(wait_time*30))
|
123 |
driver.set_window_size(int(width), int(height))
|
124 |
+
screenshot = driver.screenshot(f'{uid}-tmp.png')
|
125 |
+
|
126 |
+
yield Image.open(f'{uid}-tmp.png'), '<center>Finished loading. If loading is incomplete, restart with longer wait time',out_box,out
|
127 |
+
|
128 |
|
129 |
main_head = driver.find_element(By.CLASS_NAME, "main-content-header")
|
130 |
head_shot = main_head.screenshot(f'head-{uid}-tmp.png')
|
|
|
143 |
except Exception:
|
144 |
mes="<center>Some blocks returned an error"
|
145 |
|
|
|
146 |
except WebDriverException as e:
|
147 |
return Image.new('RGB', (1, 1)), f'<center>Please enter a valid URL of a website/host.',out_box,out
|
148 |
finally:
|
149 |
if driver:
|
150 |
driver.quit()
|
151 |
+
yield Image.open(f'{uid}-tmp.png'), mes,out_box,out
|
152 |
else:
|
153 |
+
yield None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
154 |
def load_frame(inp):
|
155 |
html_mod=f"""
|
156 |
<div id="my_game" style="height:600px;width:100%">
|
|
|
169 |
with gr.Row():
|
170 |
with gr.Column():
|
171 |
inp = gr.Textbox(label="URL (must be Public)",lines=1)
|
172 |
+
wait_t=gr.Slider(1, 10000, value=2000, label="Wait time", info="Wait for page to load. More data = Longer wait")
|
173 |
with gr.Row():
|
|
|
174 |
btn= gr.Button("Snapshot")
|
175 |
+
stop_btn=gr.Button("Stop")
|
176 |
|
177 |
with gr.Column():
|
178 |
check_h=gr.Checkbox(label="Show Header", value=True)
|
|
|
188 |
outim = gr.Image()
|
189 |
prev=gr.HTML()
|
190 |
#load_btn.click(load_frame,inp,prev)
|
191 |
+
go = btn.click(run_script,[inp,height,width,check_b,check_h,wait_t],[outim,message,outgal,out])
|
192 |
+
stop_btn.click(None,None,None,cancels=go)
|
193 |
app.queue(default_concurrency_limit=5).launch()
|