Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,32 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from fastai.vision.all import *
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
st.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
st.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
| 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 |
+
# Main function for Streamlit app
|
| 15 |
+
def main():
|
| 16 |
+
st.title("Image Classifier")
|
| 17 |
+
st.write("Upload an image to classify")
|
| 18 |
+
|
| 19 |
+
# Upload image file
|
| 20 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 21 |
+
|
| 22 |
+
# Display prediction when an image is uploaded
|
| 23 |
+
if uploaded_file is not None:
|
| 24 |
+
image = Image.open(uploaded_file)
|
| 25 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 26 |
+
st.write("Classifying...")
|
| 27 |
+
prediction, probability = predict_image(uploaded_file)
|
| 28 |
+
st.write(f"Prediction: {prediction}; Probability: {probability:.4f}")
|
| 29 |
+
|
| 30 |
+
# Run the Streamlit app
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
main()
|