Spaces:
Runtime error
Runtime error
from statistics import mode | |
import streamlit as st | |
from fastai.vision.all import * | |
from PIL import Image | |
from Processor import Processor | |
def initialize_app(): | |
return Processor(load_learner('model.pkl')) | |
def process_images(images, processor: Processor): | |
filtered_images = [] | |
for image in images: | |
image = Image.open(image) | |
if processor.filter_image(image): | |
filtered_images.append(np.asarray(image)) | |
result = processor.classify_images(filtered_images) | |
outfit = mode(result) | |
with open(f'./texts/{outfit}.txt') as text: | |
personality = text.read() | |
return {"Outfit": outfit.title(), "Personality": personality} | |
# Streamlit UI | |
processor = initialize_app() | |
st.title('Instagram Clothes Psychology (Photos)') | |
uploaded_photos = st.file_uploader(label="Upload photos", type=[ | |
'jpg', 'jpeg', 'png'], accept_multiple_files=True) | |
photos_empty = True if len(uploaded_photos) == 0 else False | |
is_clicked = st.button(label='Predict Personality', | |
disabled=photos_empty, type="primary") | |
if is_clicked: | |
with st.spinner('Please wait...'): | |
result = process_images(uploaded_photos, processor) | |
st.subheader('Your personality is..') | |
st.write(result) | |