File size: 2,811 Bytes
aead09a
 
4256684
7716718
 
 
57e4f6c
 
 
 
 
 
 
 
 
458c1fb
 
 
 
283940a
7716718
 
0b4ddd5
7716718
0b4ddd5
458c1fb
 
 
 
 
09604de
283940a
 
 
0745a74
 
57e4f6c
 
283940a
 
 
0b4ddd5
aead09a
aa30d73
bdc2bfb
 
2ff819d
 
aa30d73
661cb49
aa30d73
 
 
 
bdc2bfb
aa30d73
 
 
 
bdc2bfb
aa30d73
bdc2bfb
aa30d73
bdc2bfb
aa30d73
bdc2bfb
aead09a
 
 
 
 
 
d5ef3b7
 
 
 
458c1fb
d5ef3b7
458c1fb
 
42a1ed0
57e4f6c
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
import gradio as gr
import requests 
from bs4 import BeautifulSoup
from google_img_source_search import ReverseImageSearcher



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 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>
        imgSize()
        </div>"""

        
    return (gr.HTML(f'<h1>Total Found: {count}</h1><br>{html_out}'))

def find_it(inp):
    out=""
    try:
        #url = f'https://lens.google.com/uploadbyurl?url={inp.strip("")}'
        url = f'https://tineye.com/search/?url={inp.strip("")}'
        response = requests.get(url)
        out=response.text
        if response.status_code == 200:
            page_content = response.text
            
            soup = BeautifulSoup(page_content, "html.parser")
            print(soup.prettify())
            #articles = soup.find_all("div", class_="SoaBEf")
            #articles = soup.find_all("a")
            #articles = soup.find_all("article", class_="MQsxIb xTewfe R7GTQ keNKEd j7vNaf Cc0Z5d VkAdve GU7x0c JMJvke q4atFc")
            articles = soup.find_all("article") 
            out = soup.prettify
            print (articles)
            
    except Exception as e:
        out = e
        print (e)
    return (out)
#https://lens.google.com/uploadbyurl?url=
#https://tineye.com/search/?url=
#https://yandex.com/images/search?cbir_id=4330355%2FBhPd4CHqib3nxk9xOdS9pQ7899&rpt=imageview&url=


with gr.Blocks() as app:
    with gr.Row():
        with gr.Column():
            inp_url=gr.Textbox(label="Image URL")
            go_btn=gr.Button()
        
        inp_im=gr.Image()
    with gr.Row():
        
        html_out = gr.HTML("""""")
    go_btn.click(rev_im,inp_url,[html_out],_js=size_js)
app.launch()