Omnibus commited on
Commit
102c183
1 Parent(s): cfb9e2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -46
app.py CHANGED
@@ -29,49 +29,60 @@ def dl(inp):
29
  except Exception as e:
30
  print (e)
31
  #out = f'{e}'
32
- return out
33
 
34
- def process_vid(file):
35
  new_video_in = str(file)
36
  capture = cv2.VideoCapture(new_video_in)
37
  frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
38
  rev_img_searcher = ReverseImageSearcher()
39
  html_out=""
 
 
 
 
 
40
  try:
41
- for i in range(frame_count-1):
42
- print(i)
43
- capture.set(cv2.CAP_PROP_POS_FRAMES, i)
44
- ret, frame_f = capture.read(i)
45
- cv2.imwrite(f"{uid}-vid_tmp{i}.png", frame_f)
46
- out = os.path.abspath(f"{uid}-vid_tmp{i}.png")
47
- out_url = f'https://omnibus-reverse-image.hf.space/file={out}'
48
- print(out)
49
- res = rev_img_searcher.search(out_url)
50
- #print (res)
51
- if len(res) > 0:
52
- count = 0
53
- for search_item in res:
54
- print (f'counting {count}')
55
- count+=1
56
- out_dict={
57
- 'Title': f'{search_item.page_title}',
58
- 'Site': f'{search_item.page_url}',
59
- 'Img': f'{search_item.image_url}',
60
- }
61
- print (dir(search_item))
62
- html_out = f"""{html_out}
63
- <div>
64
- Title: {search_item.page_title}<br>
65
- Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
66
- Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
67
- <img class='my_im' src='{search_item.image_url}'><br>
68
- </div>"""
69
- return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
70
- else:
71
- pass
 
 
 
 
 
 
72
  except Exception as e:
73
- return (gr.HTML(f'{e}'))
74
- return (gr.HTML('No frame matches found.'))
75
 
76
  def process_im(file):
77
  read_file = Image.open(file)
@@ -104,15 +115,10 @@ def rev_im(image_url):
104
  Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
105
  <img class='my_im' src='{search_item.image_url}'><br>
106
  </div>"""
 
107
  return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
108
 
109
- def shuf(tog):
110
- if tog == "URL":
111
- return gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
112
- if tog == "Image":
113
- return gr.update(visible=False),gr.update(visible=True),gr.update(visible=False)
114
- if tog == "Video":
115
- return gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
116
 
117
 
118
 
@@ -132,15 +138,31 @@ with gr.Blocks() as app:
132
  vid_url=gr.Textbox(label="Video URL")
133
  vid_url_btn=gr.Button("Load URL")
134
  inp_vid=gr.Video(label="Search Video")
135
- go_btn_vid=gr.Button()
 
 
 
 
 
 
136
  gr.Column()
137
  #paste_clip = gr.Button("Paste from Clipboard")
138
  with gr.Row():
139
  html_out = gr.HTML("""""")
140
- vid_url_btn.click(dl,vid_url,inp_vid)
 
 
 
 
 
 
 
 
 
 
141
  source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
142
  inp_im.change(process_im,inp_im,[inp_url])
143
- go_btn_vid.click(process_vid,inp_vid,[html_out])
144
  go_btn_im.click(rev_im,inp_url,[html_out])
145
  go_btn_url.click(rev_im,inp_url,[html_out])
146
- app.queue(concurrency_count=10).launch()
 
29
  except Exception as e:
30
  print (e)
31
  #out = f'{e}'
32
+ return out,gr.HTML(""),"",""
33
 
34
+ def process_vid(file,cur_frame,every_n):
35
  new_video_in = str(file)
36
  capture = cv2.VideoCapture(new_video_in)
37
  frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
38
  rev_img_searcher = ReverseImageSearcher()
39
  html_out=""
40
+ count = int(every_n)
41
+ if cur_frame == "" or cur_frame==None:
42
+ start_frame = 0
43
+ elif cur_frame != "" and cur_frame!=None:
44
+ start_frame = int(cur_frame)
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)
58
+ out_cnt =0
59
+ if len(res) > 0:
60
+ #count = 0
61
+ for search_item in res:
62
+ print (f'counting {count}')
63
+ out_cnt+=1
64
+ out_dict={
65
+ 'Title': f'{search_item.page_title}',
66
+ 'Site': f'{search_item.page_url}',
67
+ 'Img': f'{search_item.image_url}',
68
+ }
69
+ print (dir(search_item))
70
+ html_out = f"""{html_out}
71
+ <div>
72
+ Title: {search_item.page_title}<br>
73
+ Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
74
+ Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
75
+ <img class='my_im' src='{search_item.image_url}'><br>
76
+ </div>"""
77
+ return (gr.HTML(f'<h1>Total Found: {out_cnt}</h1><br>{html_out}'), f"Found frame: {i}", i+int(every_n))
78
+ else:
79
+ pass
80
+ count +=1
81
+ print (i+1)
82
+ #return (None,f"Searching Frame: {i}", "")
83
  except Exception as e:
84
+ return (gr.HTML(f'{e}'),"","")
85
+ return (gr.HTML('No frame matches found.'),"","")
86
 
87
  def process_im(file):
88
  read_file = Image.open(file)
 
115
  Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
116
  <img class='my_im' src='{search_item.image_url}'><br>
117
  </div>"""
118
+
119
  return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
120
 
121
+
 
 
 
 
 
 
122
 
123
 
124
 
 
138
  vid_url=gr.Textbox(label="Video URL")
139
  vid_url_btn=gr.Button("Load URL")
140
  inp_vid=gr.Video(label="Search Video")
141
+ with gr.Row():
142
+ every_n=gr.Number(label = "Every /nth frame", value = 10)
143
+ stat_box=gr.Textbox(label="Status")
144
+ with gr.Row():
145
+ go_btn_vid=gr.Button("Start")
146
+ next_btn=gr.Button("Next")
147
+
148
  gr.Column()
149
  #paste_clip = gr.Button("Paste from Clipboard")
150
  with gr.Row():
151
  html_out = gr.HTML("""""")
152
+ with gr.Row(visible=True):
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=False),gr.update(visible=True),gr.update(visible=False)
159
+ if tog == "Video":
160
+ return gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
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],[url_box,im_box,vid_box])
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,inp_url,[html_out])
167
  go_btn_url.click(rev_im,inp_url,[html_out])
168
+ app.launch()