File size: 1,321 Bytes
0777b3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f4aa4
0777b3a
 
 
 
 
e4f4aa4
 
 
0777b3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4119868
0777b3a
 
 
 
 
 
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
from statistics import mode

import streamlit as st
from fastai.vision.all import *
from PIL import Image

from Processor import Processor


@st.experimental_singleton
def initialize_app():
    return Processor(load_learner('model.pkl'))


def process_images(images, processor: Processor):
    filtered_images = []
    result = []

    for image in images:
        image = Image.open(image)
        if processor.filter_image(image):
            filtered_images.append(np.asarray(image))
    
    for img in filtered_images:
        result.append(processor.classify_image(img)[0])

    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)

if is_clicked:
    with st.spinner('Please wait...'):
        result = process_images(uploaded_photos, processor)
        st.subheader('Your personality is..')
        st.write(result)