Omnibus commited on
Commit
1be6131
1 Parent(s): 2ac7936

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -41
app.py CHANGED
@@ -31,50 +31,53 @@ def dl(inp):
31
  #out = f'{e}'
32
  return out
33
 
34
- def process_vid(file,cur_frame):
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
  if cur_frame == "" or cur_frame==None:
41
  start_frame = 0
42
  elif cur_frame != "" and cur_frame!=None:
43
  start_frame = int(cur_frame)
44
  try:
45
  for i in range(start_frame, frame_count-1):
46
-
47
- print(i)
48
- capture.set(cv2.CAP_PROP_POS_FRAMES, i)
49
- ret, frame_f = capture.read(i)
50
- cv2.imwrite(f"{uid}-vid_tmp{i}.png", frame_f)
51
- out = os.path.abspath(f"{uid}-vid_tmp{i}.png")
52
- out_url = f'https://omnibus-reverse-image-dev.hf.space/file={out}'
53
- print(out)
54
- res = rev_img_searcher.search(out_url)
55
- #print (res)
56
- if len(res) > 0:
57
- count = 0
58
- for search_item in res:
59
- print (f'counting {count}')
60
- count+=1
61
- out_dict={
62
- 'Title': f'{search_item.page_title}',
63
- 'Site': f'{search_item.page_url}',
64
- 'Img': f'{search_item.image_url}',
65
- }
66
- print (dir(search_item))
67
- html_out = f"""{html_out}
68
- <div>
69
- Title: {search_item.page_title}<br>
70
- Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
71
- Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
72
- <img class='my_im' src='{search_item.image_url}'><br>
73
- </div>"""
74
- return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'), f"Found frame: {i}", i)
75
- else:
76
- pass
77
- yield (None,f"Searching Frame: {i}", "")
 
 
78
  except Exception as e:
79
  return (gr.HTML(f'{e}'),"","")
80
  return (gr.HTML('No frame matches found.'),"","")
@@ -113,13 +116,7 @@ def rev_im(image_url):
113
 
114
  return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
115
 
116
- def shuf(tog):
117
- if tog == "URL":
118
- return gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
119
- if tog == "Image":
120
- return gr.update(visible=False),gr.update(visible=True),gr.update(visible=False)
121
- if tog == "Video":
122
- return gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
123
 
124
 
125
 
@@ -139,6 +136,8 @@ with gr.Blocks() as app:
139
  vid_url=gr.Textbox(label="Video URL")
140
  vid_url_btn=gr.Button("Load URL")
141
  inp_vid=gr.Video(label="Search Video")
 
 
142
  stat_box=gr.Textbox(label="Status")
143
  with gr.Row():
144
  go_btn_vid=gr.Button("Start")
@@ -150,11 +149,18 @@ with gr.Blocks() as app:
150
  html_out = gr.HTML("""""")
151
  with gr.Row(visible=True):
152
  hid_box=gr.Textbox()
 
 
 
 
 
 
 
153
  next_btn.click(process_vid,[inp_vid,hid_box],[html_out,hid_box])
154
  vid_url_btn.click(dl,vid_url,inp_vid)
155
  source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
156
  inp_im.change(process_im,inp_im,[inp_url])
157
- go_btn_vid.click(process_vid,inp_vid,[html_out,stat_box,hid_box])
158
  go_btn_im.click(rev_im,inp_url,[html_out])
159
  go_btn_url.click(rev_im,inp_url,[html_out])
160
  app.launch()
 
31
  #out = f'{e}'
32
  return out
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 = 1
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
+ if len(res) > 0:
59
+ #count = 0
60
+ for search_item in res:
61
+ print (f'counting {count}')
62
+ count+=1
63
+ out_dict={
64
+ 'Title': f'{search_item.page_title}',
65
+ 'Site': f'{search_item.page_url}',
66
+ 'Img': f'{search_item.image_url}',
67
+ }
68
+ print (dir(search_item))
69
+ html_out = f"""{html_out}
70
+ <div>
71
+ Title: {search_item.page_title}<br>
72
+ Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
73
+ Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
74
+ <img class='my_im' src='{search_item.image_url}'><br>
75
+ </div>"""
76
+ return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'), f"Found frame: {i}", i)
77
+ else:
78
+ pass
79
+ count +=1
80
+ yield (None,f"Searching Frame: {i}", "")
81
  except Exception as e:
82
  return (gr.HTML(f'{e}'),"","")
83
  return (gr.HTML('No frame matches found.'),"","")
 
116
 
117
  return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
118
 
119
+
 
 
 
 
 
 
120
 
121
 
122
 
 
136
  vid_url=gr.Textbox(label="Video URL")
137
  vid_url_btn=gr.Button("Load URL")
138
  inp_vid=gr.Video(label="Search Video")
139
+ with gr.Row():
140
+ every_n=gr.Number(value = 10)
141
  stat_box=gr.Textbox(label="Status")
142
  with gr.Row():
143
  go_btn_vid=gr.Button("Start")
 
149
  html_out = gr.HTML("""""")
150
  with gr.Row(visible=True):
151
  hid_box=gr.Textbox()
152
+ def shuf(tog):
153
+ if tog == "URL":
154
+ return gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
155
+ if tog == "Image":
156
+ return gr.update(visible=False),gr.update(visible=True),gr.update(visible=False)
157
+ if tog == "Video":
158
+ return gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
159
  next_btn.click(process_vid,[inp_vid,hid_box],[html_out,hid_box])
160
  vid_url_btn.click(dl,vid_url,inp_vid)
161
  source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
162
  inp_im.change(process_im,inp_im,[inp_url])
163
+ go_btn_vid.click(process_vid,[inp_vid,hid_box,every_n],[html_out,stat_box,hid_box])
164
  go_btn_im.click(rev_im,inp_url,[html_out])
165
  go_btn_url.click(rev_im,inp_url,[html_out])
166
  app.launch()