File size: 4,927 Bytes
aead09a
 
d82da04
 
7716718
2255cf1
d238248
522ecb9
e8f283e
 
57e4f6c
 
 
 
 
 
 
 
d82da04
 
599424e
 
 
 
 
38e0d39
60fae74
599424e
 
080f581
599424e
60fae74
599424e
60fae74
599424e
 
 
60fae74
599424e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d82da04
 
2f9a5fe
e8f283e
 
522ecb9
e8f283e
 
c558940
458c1fb
 
 
 
283940a
7716718
 
0b4ddd5
7716718
0b4ddd5
458c1fb
 
 
 
 
09604de
283940a
 
 
0745a74
 
57e4f6c
283940a
0b4ddd5
aead09a
d82da04
 
 
 
 
 
 
 
 
aead09a
 
d5ef3b7
d82da04
d5ef3b7
d82da04
 
 
 
599424e
d82da04
 
599424e
60fae74
d82da04
599424e
d82da04
2255cf1
458c1fb
 
42a1ed0
be0c8c2
37ab46f
f85c515
599424e
 
aead09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import gradio as gr
import requests 
#from bs4 import BeautifulSoup
import cv2
from google_img_source_search import ReverseImageSearcher
from PIL import Image

import os 
import uuid
uid=uuid.uuid4()
size_js="""
    function imgSize(){
        var myImg = document.getElementsByClassName("my_im");
        var realWidth = myImg.naturalWidth;
        var realHeight = myImg.naturalHeight;
        alert("Original width=" + realWidth + ", " + "Original height=" + realHeight);
    }"""


def process_vid(file):
    new_video_in = str(file)
    capture = cv2.VideoCapture(new_video_in)    
    frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
    rev_img_searcher = ReverseImageSearcher()
    try:
        for i in range(frame_count-1):
            print(i)
            capture.set(cv2.CAP_PROP_POS_FRAMES, i)
            ret, frame_f = capture.read(i)
            frame_f.imwrite(f"{uid}-vid_tmp.png")
            out = os.path.abspath(f"{uid}-vid_tmp.png")
            print(out)
            res = rev_img_searcher.search(out)
            print (res)
            if len(res) > 0:
                count = 0
                for search_item in res:
                    print (f'counting {count}')
                    count+=1
                    out_dict={
                        'Title': f'{search_item.page_title}',
                        'Site': f'{search_item.page_url}',
                        'Img': f'{search_item.image_url}',
                    }
                    print (dir(search_item))
                    html_out = f"""{html_out}
                    <div>
                    Title: {search_item.page_title}<br>
                    Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
                    Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
                    <img class='my_im' src='{search_item.image_url}'><br>
                    </div>"""
                return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))
            else:
                pass
    except Exception as e:
        return (gr.HTML(f'{e}'))
    return (gr.HTML('No frame matches found.'))

def process_im(file):
    read_file = Image.open(file)
    read_file.save(f"{uid}-tmp.png")
    action_input = f"{uid}-tmp.png"
    out = os.path.abspath(action_input)
    out_url = f'https://omnibus-reverse-image.hf.space/file={out}'
    return (out_url)

def rev_im(image_url):
    #image_url = 'https://i.pinimg.com/originals/c4/50/35/c450352ac6ea8645ead206721673e8fb.png'
    out_list = []
    out_im = []
    html_out = """"""
    rev_img_searcher = ReverseImageSearcher()
    res = rev_img_searcher.search(image_url)
    count = 0
    for search_item in res:
        count+=1
        out_dict={
            'Title': f'{search_item.page_title}',
            'Site': f'{search_item.page_url}',
            'Img': f'{search_item.image_url}',
        }
        print (dir(search_item))
        html_out = f"""{html_out}
        <div>
        Title: {search_item.page_title}<br>
        Site: <a href='{search_item.page_url}' target='_blank' rel='noopener noreferrer'>{search_item.page_url}</a><br>
        Img: <a href='{search_item.image_url}' target='_blank' rel='noopener noreferrer'>{search_item.image_url}</a><br>
        <img class='my_im' src='{search_item.image_url}'><br>
        </div>"""
    return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))

def shuf(tog):
    if tog == "URL":
        return gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
    if tog == "Image":
        return gr.update(visible=False),gr.update(visible=True),gr.update(visible=False)
    if tog == "Video":
        return gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)



with gr.Blocks() as app:
    with gr.Row():
        gr.Column()
        with gr.Column():
            
            source_tog=gr.Radio(choices=["URL","Image","Video"],value="URL")
            with gr.Box(visible=True) as url_box:
                inp_url=gr.Textbox(label="Image URL")
                go_btn_url=gr.Button()
            with gr.Box(visible=False) as im_box:
                inp_im=gr.Image(label="Search Image",type='filepath')
                go_btn_im=gr.Button()
            with gr.Box(visible=False) as vid_box:
                inp_vid=gr.Video(label="Search Video",type='filepath')
                go_btn_vid=gr.Button()
        gr.Column()            
            #paste_clip = gr.Button("Paste from Clipboard")
    with gr.Row():
        
        html_out = gr.HTML("""""")
    source_tog.change(shuf,[source_tog],[url_box,im_box,vid_box])
    inp_im.change(process_im,inp_im,[inp_url])
    go_btn_vid.click(process_vid,inp_vid,[html_out])
    go_btn_im.click(rev_im,inp_url,[html_out])
    go_btn_url.click(rev_im,inp_url,[html_out])
app.launch()