Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,22 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from fastai.vision.all import *
|
| 3 |
from PIL import Image
|
| 4 |
-
|
| 5 |
-
# Load the trained model
|
| 6 |
learn = load_learner('export.pkl')
|
| 7 |
|
| 8 |
-
# Define a function to make predictions on an image
|
| 9 |
def predict_image(image):
|
| 10 |
img = PILImage.create(image)
|
| 11 |
pred, pred_idx, probs = learn.predict(img)
|
| 12 |
return pred, probs[pred_idx].item()
|
| 13 |
|
| 14 |
-
|
| 15 |
def main():
|
| 16 |
-
st.title("Image Classifier")
|
| 17 |
st.write("Upload an image to classify")
|
| 18 |
|
| 19 |
-
|
| 20 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 21 |
|
| 22 |
-
|
| 23 |
if uploaded_file is not None:
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
|
@@ -27,6 +24,6 @@ def main():
|
|
| 27 |
prediction, probability = predict_image(uploaded_file)
|
| 28 |
st.write(f"Prediction: {prediction}; Probability: {probability:.4f}")
|
| 29 |
|
| 30 |
-
|
| 31 |
if __name__ == '__main__':
|
| 32 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from fastai.vision.all import *
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
| 4 |
learn = load_learner('export.pkl')
|
| 5 |
|
|
|
|
| 6 |
def predict_image(image):
|
| 7 |
img = PILImage.create(image)
|
| 8 |
pred, pred_idx, probs = learn.predict(img)
|
| 9 |
return pred, probs[pred_idx].item()
|
| 10 |
|
| 11 |
+
|
| 12 |
def main():
|
| 13 |
+
st.title(" Gender Image Classifier")
|
| 14 |
st.write("Upload an image to classify")
|
| 15 |
|
| 16 |
+
|
| 17 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 18 |
|
| 19 |
+
|
| 20 |
if uploaded_file is not None:
|
| 21 |
image = Image.open(uploaded_file)
|
| 22 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
|
|
|
| 24 |
prediction, probability = predict_image(uploaded_file)
|
| 25 |
st.write(f"Prediction: {prediction}; Probability: {probability:.4f}")
|
| 26 |
|
| 27 |
+
|
| 28 |
if __name__ == '__main__':
|
| 29 |
main()
|