farkmu45 commited on
Commit
0777b3a
β€’
1 Parent(s): 384fa93

Initial base

Browse files
Files changed (8) hide show
  1. Processor.py +37 -0
  2. README.md +1 -1
  3. app.py +49 -0
  4. model.pkl +3 -0
  5. requirements.txt +2 -0
  6. texts/bumi.txt +1 -0
  7. texts/kue.txt +1 -0
  8. texts/mamba.txt +1 -0
Processor.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import PIL.Image as Image
2
+ import torch
3
+ from fastai.vision.all import Learner
4
+ from numpy.typing import NDArray
5
+
6
+ class Processor():
7
+ def __init__(self, learn: Learner):
8
+ self.__inference = learn
9
+ self.__model = torch.hub.load(
10
+ 'ultralytics/yolov5', 'yolov5x6', trust_repo=True)
11
+
12
+ def classify_images(self, images: list[NDArray]) -> list[str]:
13
+ result = []
14
+ class_names = self.__inference.dls.vocab
15
+
16
+ test_dl = self.__inference.dls.test_dl(images)
17
+ tensors = self.__inference.get_preds(dl=test_dl, with_decoded=True)[2]
18
+ preds = [int(t.item()) for t in tensors]
19
+
20
+ for i in preds:
21
+ result.append(class_names[i])
22
+
23
+ return result
24
+
25
+ def filter_image(self, image: Image) -> bool:
26
+ results = self.__model(image)
27
+ results = results.pandas().xyxy[0]
28
+ person_detected = 0
29
+
30
+ for name in results['name']:
31
+ if name == 'person':
32
+ person_detected += 1
33
+
34
+ if person_detected == 0 or person_detected > 1:
35
+ return False
36
+
37
+ return True
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Instagram Clothes Psychology St
3
  emoji: πŸ“‰
4
  colorFrom: purple
5
  colorTo: pink
 
1
  ---
2
+ title: Instagram Clothes Psychology (Streamlit)
3
  emoji: πŸ“‰
4
  colorFrom: purple
5
  colorTo: pink
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from statistics import mode
2
+
3
+ import streamlit as st
4
+ from fastai.vision.all import *
5
+ from PIL import Image
6
+
7
+ from Processor import Processor
8
+
9
+
10
+ @st.experimental_singleton
11
+ def initialize_app():
12
+ return Processor(load_learner('model.pkl'))
13
+
14
+
15
+ def process_images(images, processor: Processor):
16
+ filtered_images = []
17
+
18
+ for image in images:
19
+ image = Image.open(image)
20
+ if processor.filter_image(image):
21
+ filtered_images.append(np.asarray(image))
22
+
23
+ result = processor.classify_images(filtered_images)
24
+ outfit = mode(result)
25
+
26
+ with open(f'./texts/{outfit}.txt') as text:
27
+ personality = text.read()
28
+
29
+ return {"Outfit": outfit.title(), "Personality": personality}
30
+
31
+
32
+ # Streamlit UI
33
+
34
+ processor = initialize_app()
35
+
36
+ st.title('Instagram Clothes Psychology (Photos)')
37
+ uploaded_photos = st.file_uploader(label="Upload photos", type=[
38
+ 'jpg', 'jpeg', 'png'], accept_multiple_files=True)
39
+
40
+ photos_empty = True if len(uploaded_photos) == 0 else False
41
+
42
+ is_clicked = st.button(label='Predict Personality',
43
+ disabled=photos_empty, type="primary")
44
+
45
+ if is_clicked:
46
+ with st.spinner('Please wait...'):
47
+ result = process_images(uploaded_photos, processor)
48
+ st.subheader('Your personality is..')
49
+ st.write(result)
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df7a821208e325f271b6d13cca865b928275f0fa487063936b76a30f6d86dd10
3
+ size 21726339
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ opencv-python
2
+ fastai
texts/bumi.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Neutral colours -> Kalem, usually put thought before action, cool-headed, usually called as "mom of the group", but is usually confused with someone's action towards them being portrayed as nice or effort in liking them, super dense when it comes to love
texts/kue.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Bright colours -> Happy pills, ceria, but has sensitive hearts that needs to be toughened, embraces their feminine side
texts/mamba.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Dark colours -> Emo :), most of them usually has a harsh personality with soft hearts, likes to be shown that they are very independent while in the other hand craves for attention,