Spaces:
No application file
No application file
rimasalshehri
commited on
Commit
•
05002be
1
Parent(s):
da84461
Delete app.py
Browse files
app.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""demo.ipynb
|
3 |
-
Automatically generated by Colab.
|
4 |
-
Original file is located at
|
5 |
-
https://colab.research.google.com/drive/10nAdNOzeCbnza9ZenZqOLtvBYn8BKlk5
|
6 |
-
"""
|
7 |
-
|
8 |
-
import streamlit as st
|
9 |
-
|
10 |
-
from PIL import Image
|
11 |
-
import numpy as np
|
12 |
-
from joblib import load
|
13 |
-
from skimage.transform import resize
|
14 |
-
import os
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
def load_model():
|
20 |
-
# Ensure the model path is correct and accessible from your current directory
|
21 |
-
model_path = 'svm_model3.joblib' # Update this path to where you've saved your model
|
22 |
-
if os.path.exists(model_path):
|
23 |
-
model = load(model_path)
|
24 |
-
st.write("Model loaded successfully!")
|
25 |
-
else:
|
26 |
-
st.error("Model file not found.")
|
27 |
-
return model
|
28 |
-
|
29 |
-
def classify_image(image, model):
|
30 |
-
image = np.array(image.convert('RGB'))
|
31 |
-
image_resized = resize(image, (128, 128), anti_aliasing=True)
|
32 |
-
image_reshaped = image_resized.reshape(-1, image_resized.shape[-1])
|
33 |
-
prediction = model.predict(image_reshaped)
|
34 |
-
return prediction[0]
|
35 |
-
|
36 |
-
|
37 |
-
model = load_model() # Load the model on startup
|
38 |
-
|
39 |
-
# Mapping of Monk classes to colors
|
40 |
-
class_colors= {
|
41 |
-
'1': [2, 3, 4],
|
42 |
-
'2': [5, 6],
|
43 |
-
'3': [7, 8],
|
44 |
-
'4': [9, 10],
|
45 |
-
}
|
46 |
-
|
47 |
-
|
48 |
-
# Function to display the Monk class color
|
49 |
-
def display_monk_class_color(prediction):
|
50 |
-
color = monk_colors.get(prediction, 'gray') # Default to gray if class not found
|
51 |
-
st.write(f"Monk Class: {prediction}")
|
52 |
-
st.markdown(f"<div style='width:100px; height:50px; background-color:{color};'></div>", unsafe_allow_html=True)
|
53 |
-
|
54 |
-
st.title('Skin Tone Classification')
|
55 |
-
|
56 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
57 |
-
if uploaded_file is not None:
|
58 |
-
image = Image.open(uploaded_file)
|
59 |
-
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
60 |
-
|
61 |
-
if st.button('Classify'):
|
62 |
-
prediction = classify_image(image, model)
|
63 |
-
#display_monk_class_color(prediction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|