-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (34 loc) · 1.45 KB
/
utils.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
import numpy as np
import pandas as pd
import streamlit as st
from PIL import Image
def visualization_results(input_format, threshold):
data = []
input_format = dict(sorted(input_format.items(), key=lambda item: item[1], reverse=True))
col1, col2 = st.columns([1, 1])
count = 0
for i in input_format.items():
if i[1] >= threshold / 100:
count += 1
df = pd.DataFrame()
data.append([i[0].split('/')[len(i[0].split('/'))-1], i[1]])
df = df.append(data)
df = df.rename(columns={0: "Image", 1: "Cosine distance"})
if count == 0:
st.info(f"No images for {threshold} or above cosine distance, %")
else:
for _, i in enumerate(input_format.items(), 1):
with col1:
try:
if i[1] >= threshold / 100:
not_corr_path = i[0].split('/')
path_to_image = '/app/indexes/' + '/'.join([not_corr_path[-i] for i in range(1,4)][::-1])
image = Image.open(path_to_image)
caption = f"{path_to_image.split('/')[len(path_to_image.split('/'))-1]}, {i[1]}"
st.image(image, caption=caption)
except:
pass
with col2:
if _ == 1:
st.write("Output cosine distance")
st.dataframe(df.style.text_gradient(axis=0, cmap='Spectral'))