Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,12 +18,41 @@ size_js="""
|
|
| 18 |
|
| 19 |
|
| 20 |
def process_vid(file):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def process_im(file):
|
| 29 |
read_file = Image.open(file)
|
|
@@ -76,11 +105,13 @@ with gr.Blocks() as app:
|
|
| 76 |
source_tog=gr.Radio(choices=["URL","Image","Video"],value="URL")
|
| 77 |
with gr.Box(visible=True) as url_box:
|
| 78 |
inp_url=gr.Textbox(label="Image URL")
|
|
|
|
| 79 |
with gr.Box(visible=False) as im_box:
|
| 80 |
inp_im=gr.Image(label="Search Image",type='filepath')
|
| 81 |
-
|
|
|
|
| 82 |
inp_vid=gr.Video(label="Search Video",type='filepath')
|
| 83 |
-
|
| 84 |
gr.Column()
|
| 85 |
#paste_clip = gr.Button("Paste from Clipboard")
|
| 86 |
with gr.Row():
|
|
@@ -88,7 +119,7 @@ with gr.Blocks() as app:
|
|
| 88 |
html_out = gr.HTML("""""")
|
| 89 |
source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
|
| 90 |
inp_im.change(process_im,inp_im,[inp_url])
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
app.launch()
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def process_vid(file):
|
| 21 |
+
new_video_in = str(file)
|
| 22 |
+
capture = cv2.VideoCapture(new_video_in)
|
| 23 |
+
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 24 |
+
rev_img_searcher = ReverseImageSearcher()
|
| 25 |
+
try:
|
| 26 |
+
for i in frame_count-1:
|
| 27 |
+
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 28 |
+
ret, frame_f = capture.read(i)
|
| 29 |
+
frame_f.write(f"{uid}-vid_tmp.png")
|
| 30 |
+
out = os.path.abspath(f"{uid}-vid_tmp.png")
|
| 31 |
+
|
| 32 |
+
res = rev_img_searcher.search(out)
|
| 33 |
+
if len(res) > 0:
|
| 34 |
+
count = 0
|
| 35 |
+
for search_item in res:
|
| 36 |
+
count+=1
|
| 37 |
+
out_dict={
|
| 38 |
+
'Title': f'{search_item.page_title}',
|
| 39 |
+
'Site': f'{search_item.page_url}',
|
| 40 |
+
'Img': f'{search_item.image_url}',
|
| 41 |
+
}
|
| 42 |
+
print (dir(search_item))
|
| 43 |
+
html_out = f"""{html_out}
|
| 44 |
+
<div>
|
| 45 |
+
Title: {search_item.page_title}<br>
|
| 46 |
+
Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
|
| 47 |
+
Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
|
| 48 |
+
<img class='my_im' src='{search_item.image_url}'><br>
|
| 49 |
+
</div>"""
|
| 50 |
+
return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
|
| 51 |
+
else:
|
| 52 |
+
pass
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return (gr.HTML(f'{e}'))
|
| 55 |
+
return (gr.HTML('No frame matches found.'))
|
| 56 |
|
| 57 |
def process_im(file):
|
| 58 |
read_file = Image.open(file)
|
|
|
|
| 105 |
source_tog=gr.Radio(choices=["URL","Image","Video"],value="URL")
|
| 106 |
with gr.Box(visible=True) as url_box:
|
| 107 |
inp_url=gr.Textbox(label="Image URL")
|
| 108 |
+
go_btn_url=gr.Button()
|
| 109 |
with gr.Box(visible=False) as im_box:
|
| 110 |
inp_im=gr.Image(label="Search Image",type='filepath')
|
| 111 |
+
go_btn_im=gr.Button()
|
| 112 |
+
with gr.Box(visible=False) as vid_box:
|
| 113 |
inp_vid=gr.Video(label="Search Video",type='filepath')
|
| 114 |
+
go_btn_vid=gr.Button()
|
| 115 |
gr.Column()
|
| 116 |
#paste_clip = gr.Button("Paste from Clipboard")
|
| 117 |
with gr.Row():
|
|
|
|
| 119 |
html_out = gr.HTML("""""")
|
| 120 |
source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
|
| 121 |
inp_im.change(process_im,inp_im,[inp_url])
|
| 122 |
+
go_btn_vid.click(process_vid,inp_vid,[url_box,im_box,vid_box])
|
| 123 |
+
go_btn_im.click(rev_im,inp_url,[html_out])
|
| 124 |
+
go_btn_url.click(rev_im,inp_url,[html_out])
|
| 125 |
app.launch()
|