File size: 2,605 Bytes
f7b6c7e a5cb4ef 5381f67 3a3bb19 55315c3 f9f9eae f7b6c7e a5cb4ef f9f9eae 8df0b72 d760786 1cbcc67 8df0b72 af858b4 a5cb4ef af858b4 a5cb4ef af858b4 a5cb4ef af858b4 8df0b72 af858b4 8df0b72 a5cb4ef 8df0b72 a5cb4ef 8df0b72 71e4505 8df0b72 63d858e d760786 f9f9eae d760786 f9f9eae d760786 f9f9eae a5cb4ef 71e4505 f9f9eae af858b4 d760786 f9f9eae d760786 f9f9eae af858b4 f9f9eae a5cb4ef 63d858e a5cb4ef |
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 |
import streamlit as st
from main import *
from setup import *
from PIL import Image
import time
def show_result(search_request,
search_result,
img_dir,
container,
search_time) :
thumbnail_width = 300
container.header("It took me "+ "{:.2f}".format(search_time)+ " sec to find \"" +search_request+ "\" for you !")
i = 0
for _ in range(0, 3):
for col in container.columns(2):
if i >= len(search_result):
break
image_name, comment, score = search_result[i]
# Загрузка изображения
image = Image.open(img_dir + image_name)
# Выравнивание изображения по ширине
image_width, image_height = image.size
aspect_ratio = thumbnail_width / image_width
new_height = int(image_height * aspect_ratio)
resized_image = image.resize((thumbnail_width, new_height), Image.ANTIALIAS)
# Добавление подписи
if score != '' :
sim_score = f"{float(100 * score):.2f}"
sim='similarity='+sim_score + "%"
col.markdown(comment)
col.markdown(f'<p style="font-size: 10px;">{sim}</p>', unsafe_allow_html=True)
else :
# Вывод изображения в контейнер
col.markdown(comment)
col.image(resized_image, width=thumbnail_width)
i = i + 1
return
def show_landing() :
st.title('Find my pic!')
search_request = st.text_input('Search for images',
'Search ...')
col1, col2 = st.columns(2)
if col1.button('Find!') and os.path.exists(IMAGE_DIR) :
results = st.container()
start_time = time.time()
search_result = search(search_request)
end_time = time.time()
show_result(search_request,
search_result,
IMAGE_DIR+'/',
results,
end_time - start_time)
if col2.button('Find with faiss!') and os.path.exists(IMAGE_DIR) :
results = st.container()
start_time = time.time()
search_result = searchWithFaiss(search_request)
end_time = time.time()
show_result(search_request,
search_result,
IMAGE_DIR+'/',
results,
end_time - start_time)
return
downlad_images()
show_landing() |