Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -45,13 +45,13 @@ def process_vid(file,cur_frame,every_n):
|
|
45 |
try:
|
46 |
for i in range(start_frame, frame_count-1):
|
47 |
if count == int(every_n):
|
48 |
-
count =
|
49 |
print(i)
|
50 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
51 |
ret, frame_f = capture.read(i)
|
52 |
cv2.imwrite(f"{uid}-vid_tmp{i}.png", frame_f)
|
53 |
out = os.path.abspath(f"{uid}-vid_tmp{i}.png")
|
54 |
-
out_url = f'https://omnibus-reverse-image.hf.space/file={out}'
|
55 |
print(out)
|
56 |
res = rev_img_searcher.search(out_url)
|
57 |
#print (res)
|
@@ -84,21 +84,28 @@ def process_vid(file,cur_frame,every_n):
|
|
84 |
return (gr.HTML(f'{e}'),"","")
|
85 |
return (gr.HTML('No frame matches found.'),"","")
|
86 |
|
87 |
-
def process_im(file):
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
94 |
|
95 |
-
def rev_im(
|
96 |
#image_url = 'https://i.pinimg.com/originals/c4/50/35/c450352ac6ea8645ead206721673e8fb.png'
|
97 |
out_list = []
|
98 |
out_im = []
|
99 |
html_out = """"""
|
|
|
|
|
|
|
|
|
100 |
rev_img_searcher = ReverseImageSearcher()
|
101 |
-
res = rev_img_searcher.search(
|
102 |
count = 0
|
103 |
for search_item in res:
|
104 |
count+=1
|
@@ -127,11 +134,10 @@ with gr.Blocks() as app:
|
|
127 |
gr.Column()
|
128 |
with gr.Column():
|
129 |
|
130 |
-
source_tog=gr.Radio(choices=["
|
131 |
-
with gr.Box(visible=True) as
|
132 |
inp_url=gr.Textbox(label="Image URL")
|
133 |
-
|
134 |
-
with gr.Box(visible=False) as im_box:
|
135 |
inp_im=gr.Image(label="Search Image",type='filepath')
|
136 |
go_btn_im=gr.Button()
|
137 |
with gr.Box(visible=False) as vid_box:
|
@@ -152,17 +158,18 @@ with gr.Blocks() as app:
|
|
152 |
with gr.Row(visible=False):
|
153 |
hid_box=gr.Textbox()
|
154 |
def shuf(tog):
|
155 |
-
if tog == "URL":
|
156 |
-
return gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
|
157 |
if tog == "Image":
|
158 |
-
return gr.update(visible=
|
159 |
if tog == "Video":
|
160 |
-
return gr.update(visible=False),gr.update(visible=
|
|
|
|
|
|
|
161 |
next_btn.click(process_vid,[inp_vid,hid_box,every_n],[html_out,stat_box,hid_box])
|
162 |
vid_url_btn.click(dl,vid_url,[inp_vid,html_out,stat_box,hid_box])
|
163 |
-
source_tog.change(shuf,[source_tog],[
|
164 |
-
inp_im.change(process_im,inp_im,[inp_url])
|
165 |
go_btn_vid.click(process_vid,[inp_vid,hid_box,every_n],[html_out,stat_box,hid_box])
|
166 |
-
go_btn_im.click(rev_im,
|
167 |
-
go_btn_url.click(rev_im,inp_url,[html_out])
|
168 |
-
app.
|
|
|
45 |
try:
|
46 |
for i in range(start_frame, frame_count-1):
|
47 |
if count == int(every_n):
|
48 |
+
count = 1
|
49 |
print(i)
|
50 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
51 |
ret, frame_f = capture.read(i)
|
52 |
cv2.imwrite(f"{uid}-vid_tmp{i}.png", frame_f)
|
53 |
out = os.path.abspath(f"{uid}-vid_tmp{i}.png")
|
54 |
+
out_url = f'https://omnibus-reverse-image-dev.hf.space/file={out}'
|
55 |
print(out)
|
56 |
res = rev_img_searcher.search(out_url)
|
57 |
#print (res)
|
|
|
84 |
return (gr.HTML(f'{e}'),"","")
|
85 |
return (gr.HTML('No frame matches found.'),"","")
|
86 |
|
87 |
+
def process_im(file,url):
|
88 |
+
if not url.startswith("https://omnibus"):
|
89 |
+
return url
|
90 |
+
else:
|
91 |
+
read_file = Image.open(file)
|
92 |
+
read_file.save(f"{uid}-tmp.png")
|
93 |
+
action_input = f"{uid}-tmp.png"
|
94 |
+
out = os.path.abspath(action_input)
|
95 |
+
out_url = f'https://omnibus-reverse-image.hf.space/file={out}'
|
96 |
+
return (out_url)
|
97 |
|
98 |
+
def rev_im(image):
|
99 |
#image_url = 'https://i.pinimg.com/originals/c4/50/35/c450352ac6ea8645ead206721673e8fb.png'
|
100 |
out_list = []
|
101 |
out_im = []
|
102 |
html_out = """"""
|
103 |
+
image=cv2.imread(image)
|
104 |
+
cv2.imwrite(f"{uid}-im_tmp.png", image)
|
105 |
+
out = os.path.abspath(f"{uid}-im_tmp.png")
|
106 |
+
out_url = f'https://omnibus-reverse-image-dev.hf.space/file={out}'
|
107 |
rev_img_searcher = ReverseImageSearcher()
|
108 |
+
res = rev_img_searcher.search(out_url)
|
109 |
count = 0
|
110 |
for search_item in res:
|
111 |
count+=1
|
|
|
134 |
gr.Column()
|
135 |
with gr.Column():
|
136 |
|
137 |
+
source_tog=gr.Radio(choices=["Image","Video"],value="Image")
|
138 |
+
with gr.Box(visible=True) as im_box:
|
139 |
inp_url=gr.Textbox(label="Image URL")
|
140 |
+
load_im_btn=gr.Button("Load Image")
|
|
|
141 |
inp_im=gr.Image(label="Search Image",type='filepath')
|
142 |
go_btn_im=gr.Button()
|
143 |
with gr.Box(visible=False) as vid_box:
|
|
|
158 |
with gr.Row(visible=False):
|
159 |
hid_box=gr.Textbox()
|
160 |
def shuf(tog):
|
|
|
|
|
161 |
if tog == "Image":
|
162 |
+
return gr.update(visible=True),gr.update(visible=False)
|
163 |
if tog == "Video":
|
164 |
+
return gr.update(visible=False),gr.update(visible=True)
|
165 |
+
def load_image(url):
|
166 |
+
return url
|
167 |
+
load_im_btn.click(load_image,inp_url,inp_im)
|
168 |
next_btn.click(process_vid,[inp_vid,hid_box,every_n],[html_out,stat_box,hid_box])
|
169 |
vid_url_btn.click(dl,vid_url,[inp_vid,html_out,stat_box,hid_box])
|
170 |
+
source_tog.change(shuf,[source_tog],[im_box,vid_box])
|
171 |
+
#inp_im.change(process_im,[inp_im,inp_url],[inp_url])
|
172 |
go_btn_vid.click(process_vid,[inp_vid,hid_box,every_n],[html_out,stat_box,hid_box])
|
173 |
+
go_btn_im.click(rev_im,inp_im,[html_out])
|
174 |
+
#go_btn_url.click(rev_im,inp_url,[html_out])
|
175 |
+
app.launch()
|