-
Notifications
You must be signed in to change notification settings - Fork 7
/
web_search.py
59 lines (46 loc) · 2.29 KB
/
web_search.py
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
import json
import streamlit as st
from lingolens import *
if __name__ == '__main__':
all_languages = json.load(open('languages.json'))
language_names = list(all_languages.keys())
selected_lang_names = st.multiselect(
'Choose languages to filter results',
language_names,
['English', 'Polish', 'Korean'],
)
all_countries = json.load(open('countries.json'))
countries_names = list(all_countries.keys())
selected_country_names = st.multiselect(
'Choose countries to search',
countries_names,
[],
)
st.markdown('If you have search results distorted by the presence of some object, try to remove it through with [Cleanup.pictures](https://cleanup.pictures/) and use the processed image.')
uploaded_file = st.file_uploader("Choose an image file to search")
if uploaded_file is not None:
file_content = uploaded_file.read()
st.image(uploaded_file, caption=uploaded_file.name, width=500)
langs = []
if not selected_country_names:
selected_country_names = [""]
for n in selected_lang_names:
for c in selected_country_names:
lang = all_languages[n]
country = all_countries[c]
if not country:
langs.append(lang)
else:
langs.append(f'{lang}-{country.upper()}')
langs = list(set(langs))
st.write(f'A search will be conducted with the following language-country combinations: {", ".join(langs)}')
file_name = f'{uploaded_file.name}_lens_report_{"_".join(langs)}.html'
if st.button(f'Search in Google Lens with selected languages', type="primary"):
report_html, results_count = search_and_generate_report(uploaded_file.name, file_content, langs)
if not results_count:
st.markdown('No results, probable issues with Google captcha, try to run tool [locally](https://github.com/OSINT-mindset/lingolens#usage).')
else:
with open(file_name, 'w', encoding='utf-8') as file:
file.write(report_html)
with open(file_name) as f:
st.download_button(f'Download report ({results_count} results)', f, mime='text/html', file_name=file_name)