Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,13 +28,13 @@ def get_concat_v_cut(in1, in2):
|
|
| 28 |
im1=Image.open(in1)
|
| 29 |
im2=Image.open(in2)
|
| 30 |
dst = Image.new(
|
| 31 |
-
'RGB', (min(im1.width, im2.width), im1.height + im2.height
|
| 32 |
dst.paste(im1, (0, 0))
|
| 33 |
-
dst.paste(im2, (0, im1.height
|
| 34 |
return dst
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
def run_script(url: str, height: int, width: int, check_b,check_h):
|
| 39 |
mes_box=[]
|
| 40 |
out_box=[]
|
|
@@ -53,39 +53,13 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
|
|
| 53 |
html=driver.page_source
|
| 54 |
#print (driver.html)
|
| 55 |
driver.implicitly_wait(30)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
driver.set_window_size(int(width), int(height))
|
| 60 |
-
page = driver.find_element(By.TAG_NAME, "html")
|
| 61 |
-
driver.execute_script(
|
| 62 |
-
print (dir(page))
|
| 63 |
-
#page.send_keys('theme','gab-black')
|
| 64 |
-
dk=page.get_attribute('theme')
|
| 65 |
-
print (dir(dk))
|
| 66 |
-
print (page.get_attribute('theme'))
|
| 67 |
-
#driver.execute_script("arguments[0].theme='gab-black';",page)
|
| 68 |
-
print (page.get_attribute('theme'))
|
| 69 |
-
print(dir(driver))
|
| 70 |
-
#driver.get(driver.getCurrentUrl())
|
| 71 |
-
#driver.navigate().refresh()
|
| 72 |
main_head = driver.find_element(By.CLASS_NAME, "main-content-header")
|
| 73 |
-
#driver.execute_script("arguments[0].style='background:#474747;color:#055550!important;';",main_head)
|
| 74 |
-
|
| 75 |
head_shot = main_head.screenshot(f'head-{uid}-tmp.png')
|
| 76 |
-
|
| 77 |
obj = driver.find_element(By.CLASS_NAME, "main")
|
| 78 |
messages = driver.find_elements(By.CLASS_NAME, "message")
|
| 79 |
-
message_css = driver.find_elements(By.CSS_SELECTOR, ".message-bubble .message")
|
| 80 |
-
#print(f'message_css:: {message_css.text}')
|
| 81 |
-
#page.get_attribute('theme')
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
driver.execute_script(f"arguments[0].style='{css_bub}';",message_css)
|
| 85 |
-
|
| 86 |
-
#print (len(messages))
|
| 87 |
-
#mes_blocks=len(messages)%2
|
| 88 |
-
|
| 89 |
for i,ea in enumerate(check_b):
|
| 90 |
try:
|
| 91 |
ea = int(ea)
|
|
@@ -96,10 +70,6 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
|
|
| 96 |
im_roll = get_concat_v_cut(f'{i}-{uid}-tmp.png',f'{i+1}-{uid}-tmp.png')
|
| 97 |
im_roll.save(f'comb{i}-{uid}-tmp.png')
|
| 98 |
out_box.append(f'comb{i}-{uid}-tmp.png')
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
print(f'out_box:: {out_box}')
|
| 102 |
-
#mes_box.clear()
|
| 103 |
except Exception:
|
| 104 |
mes="<center>Some blocks returned an error"
|
| 105 |
if out_box:
|
|
@@ -118,51 +88,12 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
|
|
| 118 |
head_paste = get_concat_v_cut(f'head-{uid}-tmp.png',f'comb-{uid}-tmp.png')
|
| 119 |
head_paste.save(f'comb-{uid}-tmp.png')
|
| 120 |
out = f'comb-{uid}-tmp.png'
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
'''
|
| 127 |
-
for i,mes in enumerate(messages):
|
| 128 |
-
print (mes.text)
|
| 129 |
-
if not (i%2):
|
| 130 |
-
messages[i].screenshot(f'{i}-{uid}-tmp.png')
|
| 131 |
-
messages[i+1].screenshot(f'{i+1}-{uid}-tmp.png')
|
| 132 |
-
mes_box.append(())
|
| 133 |
-
out_box.append(get_concat_v_cut(f'{i}-{uid}-tmp.png',f'{i+1}-{uid}-tmp.png'))
|
| 134 |
-
print(f'out_box:: {out_box}')
|
| 135 |
-
#mes_box.clear()
|
| 136 |
-
'''
|
| 137 |
-
#obj = driver.find_element(By.ID, "app-container")
|
| 138 |
-
#obj = driver.find_element(By.ID, "conversation-feed")
|
| 139 |
-
#obj = driver.find_element_by_id("in_html")
|
| 140 |
-
######################
|
| 141 |
-
#inp = driver.find_element("id","input")
|
| 142 |
-
'''
|
| 143 |
-
find_element(By.ID, "id")
|
| 144 |
-
find_element(By.NAME, "name")
|
| 145 |
-
find_element(By.XPATH, "xpath")
|
| 146 |
-
find_element(By.LINK_TEXT, "link text")
|
| 147 |
-
find_element(By.PARTIAL_LINK_TEXT, "partial link text")
|
| 148 |
-
find_element(By.TAG_NAME, "tag name")
|
| 149 |
-
find_element(By.CLASS_NAME, "class name")
|
| 150 |
-
find_element(By.CSS_SELECTOR, "css selector")
|
| 151 |
-
'''
|
| 152 |
-
#inp.send_keys("test")
|
| 153 |
-
######################
|
| 154 |
-
cookie_jar = []
|
| 155 |
-
#cookie_jar.append(driver.get_cookies())
|
| 156 |
-
#print(cookie_jar)
|
| 157 |
screenshot = obj.screenshot(f'{uid}-tmp.png')
|
| 158 |
-
#screenshot = obj.get_screenshot_as_png()
|
| 159 |
except WebDriverException as e:
|
| 160 |
-
return Image.new('RGB', (1, 1)), f'<center>
|
| 161 |
finally:
|
| 162 |
if driver:
|
| 163 |
driver.quit()
|
| 164 |
-
|
| 165 |
-
#return [Image.open(BytesIO(screenshot)), 'operation success.',cookie_jar,html]
|
| 166 |
return Image.open(f'{uid}-tmp.png'), mes,out_box,out
|
| 167 |
else:
|
| 168 |
return None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
|
@@ -171,12 +102,12 @@ with gr.Blocks() as app:
|
|
| 171 |
|
| 172 |
with gr.Row():
|
| 173 |
with gr.Column():
|
| 174 |
-
inp = gr.Textbox(label="URL",lines=1)
|
| 175 |
btn= gr.Button()
|
| 176 |
|
| 177 |
with gr.Column():
|
| 178 |
check_h=gr.Checkbox(label="Show Header", value=True)
|
| 179 |
-
check_b=gr.CheckboxGroup(label="Chatblocks", choices=[1,2,3,4,5,6,7,8,9,10], value=[1])
|
| 180 |
with gr.Row():
|
| 181 |
height=gr.Number(label="Height", value=4096)
|
| 182 |
width=gr.Number(label="Width",value=800)
|
|
@@ -188,4 +119,4 @@ with gr.Blocks() as app:
|
|
| 188 |
outim = gr.Image()
|
| 189 |
|
| 190 |
btn.click(run_script,[inp,height,width,check_b,check_h],[outim,message,outgal,out])
|
| 191 |
-
app.launch()
|
|
|
|
| 28 |
im1=Image.open(in1)
|
| 29 |
im2=Image.open(in2)
|
| 30 |
dst = Image.new(
|
| 31 |
+
'RGB', (min(im1.width, im2.width), im1.height + im2.height))
|
| 32 |
dst.paste(im1, (0, 0))
|
| 33 |
+
dst.paste(im2, (0, im1.height))
|
| 34 |
return dst
|
| 35 |
|
| 36 |
+
|
| 37 |
+
|
| 38 |
def run_script(url: str, height: int, width: int, check_b,check_h):
|
| 39 |
mes_box=[]
|
| 40 |
out_box=[]
|
|
|
|
| 53 |
html=driver.page_source
|
| 54 |
#print (driver.html)
|
| 55 |
driver.implicitly_wait(30)
|
|
|
|
|
|
|
|
|
|
| 56 |
driver.set_window_size(int(width), int(height))
|
| 57 |
+
#page = driver.find_element(By.TAG_NAME, "html")
|
| 58 |
+
#driver.execute_script("arguments[0].style.background = 'blue';",page)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
main_head = driver.find_element(By.CLASS_NAME, "main-content-header")
|
|
|
|
|
|
|
| 60 |
head_shot = main_head.screenshot(f'head-{uid}-tmp.png')
|
|
|
|
| 61 |
obj = driver.find_element(By.CLASS_NAME, "main")
|
| 62 |
messages = driver.find_elements(By.CLASS_NAME, "message")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
for i,ea in enumerate(check_b):
|
| 64 |
try:
|
| 65 |
ea = int(ea)
|
|
|
|
| 70 |
im_roll = get_concat_v_cut(f'{i}-{uid}-tmp.png',f'{i+1}-{uid}-tmp.png')
|
| 71 |
im_roll.save(f'comb{i}-{uid}-tmp.png')
|
| 72 |
out_box.append(f'comb{i}-{uid}-tmp.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
except Exception:
|
| 74 |
mes="<center>Some blocks returned an error"
|
| 75 |
if out_box:
|
|
|
|
| 88 |
head_paste = get_concat_v_cut(f'head-{uid}-tmp.png',f'comb-{uid}-tmp.png')
|
| 89 |
head_paste.save(f'comb-{uid}-tmp.png')
|
| 90 |
out = f'comb-{uid}-tmp.png'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
screenshot = obj.screenshot(f'{uid}-tmp.png')
|
|
|
|
| 92 |
except WebDriverException as e:
|
| 93 |
+
return Image.new('RGB', (1, 1)), f'<center>Please enter a valid URL of a website/host.',out_box,out
|
| 94 |
finally:
|
| 95 |
if driver:
|
| 96 |
driver.quit()
|
|
|
|
|
|
|
| 97 |
return Image.open(f'{uid}-tmp.png'), mes,out_box,out
|
| 98 |
else:
|
| 99 |
return None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
|
|
|
| 102 |
|
| 103 |
with gr.Row():
|
| 104 |
with gr.Column():
|
| 105 |
+
inp = gr.Textbox(label="URL (must be Public)",lines=1)
|
| 106 |
btn= gr.Button()
|
| 107 |
|
| 108 |
with gr.Column():
|
| 109 |
check_h=gr.Checkbox(label="Show Header", value=True)
|
| 110 |
+
check_b=gr.CheckboxGroup(label="Chatblocks", choices=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], value=[1])
|
| 111 |
with gr.Row():
|
| 112 |
height=gr.Number(label="Height", value=4096)
|
| 113 |
width=gr.Number(label="Width",value=800)
|
|
|
|
| 119 |
outim = gr.Image()
|
| 120 |
|
| 121 |
btn.click(run_script,[inp,height,width,check_b,check_h],[outim,message,outgal,out])
|
| 122 |
+
app.queue(default_concurrency_limit=5).launch()
|