Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# coding: utf-8
|
| 3 |
+
#dosyayı py olarak kaydet ve komut satırını kullanarak streamlit run streamlit.py
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from tensorflow.keras.models import load_model
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import numpy as np
|
| 8 |
+
import cv2
|
| 9 |
+
model=load_model('date_fruit_class_cnn.h5')
|
| 10 |
+
def process_image(img):
|
| 11 |
+
img=img.resize((224,224))
|
| 12 |
+
img=np.array(img)
|
| 13 |
+
img=img[:,:, :3] # Remove the alpha channel
|
| 14 |
+
img=img/255.0
|
| 15 |
+
img=np.expand_dims(img,axis=0)
|
| 16 |
+
return img
|
| 17 |
+
st.title('Date Fruit Classification')
|
| 18 |
+
st.write('Please choose an image so that the AI model can predict the type of date.')
|
| 19 |
+
file=st.file_uploader('Pick an image', type= ['jpg','jpeg','png'])
|
| 20 |
+
class_names=['Ajwa', 'Medjool','Nabtat Ali', 'Shaishe', 'Sugaey', 'Galaxy', 'Meneifi','Rutab', 'Sokari']
|
| 21 |
+
if file is not None:
|
| 22 |
+
img=Image.open(file)
|
| 23 |
+
st.image(img,caption='The image: ')
|
| 24 |
+
image=process_image(img)
|
| 25 |
+
prediction=model.predict(image)
|
| 26 |
+
predicted_class=np.argmax(prediction)
|
| 27 |
+
st.write('Probability Distribution')
|
| 28 |
+
st.write(prediction)
|
| 29 |
+
st.write("Prediction: ",class_names[predicted_class])
|