ahmadmac commited on
Commit
0634e08
·
verified ·
1 Parent(s): 7486b99

Update app.py

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