Spaces:
Sleeping
Sleeping
| import numpy as np | |
| from PIL import Image, ImageOps | |
| import streamlit as st | |
| import requests | |
| from utils import FashionSearch | |
| fashion = FashionSearch() | |
| st.title("Fashion Search") | |
| sample_image_url = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQgQrpNAmfVOPQ_3C2FBgEcfKjUiDf3qoKmgQ&usqp=CAU' | |
| image = None | |
| with st.sidebar: | |
| tab_url, tab_upload, tab_cam = st.tabs(['URL', 'Upload', 'Camera']) | |
| with tab_url: | |
| image_url = st.text_input( | |
| label="Enter the Image URL", value=sample_image_url, key='tab_url') | |
| with tab_upload: | |
| image_upload = st.file_uploader( | |
| label='Upload the Image', type=['jpg', 'jpeg', 'png'], key='tab_upload') | |
| with tab_cam: | |
| image_webcam = st.camera_input( | |
| label="π Simle for the camera π·", key='tab_cam') | |
| if image_upload or image_webcam: | |
| if image_webcam: | |
| image = Image.open(image_webcam) | |
| else: | |
| image = Image.open(image_upload) | |
| else: | |
| try: | |
| image = Image.open(requests.get(url=image_url, stream=True).raw) | |
| st.image(image=ImageOps.scale(image, factor=0.2)) | |
| except: | |
| st.warning("Please use a different URL π", icon="β ") | |
| if image: | |
| rows = [st.columns(4) for row in range(4)] | |
| cols = [col for row in rows for col in row] | |
| suggestions = fashion.find_k_neighbors(sample_img=image) | |
| for col, id in zip(cols, suggestions): | |
| img = Image.open(requests.get(fashion.image_link[int(id)], stream=True).raw) | |
| col.image(img) | |
| else: | |
| st.info('Load an Image to get fashion suggestions', icon="π€") | |
| # st.write(st.session_state) |