Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
satrio142 authored Dec 19, 2023
1 parent 3b8b5c6 commit 374f5ee
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,28 @@ async def predict_image(img: UploadFile, response: Response):
img = load_img(file_like_object, target_size=(150, 150))

# Load the model
model = load_model('model1.h5')
model = load_model('model.h5')

# Prepare the image for prediction
image = img_to_array(img)
image = np.expand_dims(image, axis=0)

# Predict the class of the image
arr = model.predict(image)
if arr[0][0]==1:
labels='Fresh Apples'
elif arr[0][1]==1:
labels='Fresh Banana'
elif arr[0][2]==1:
labels='Fresh Oranges'
elif arr[0][3]==1:
labels='Rotten Apples'
elif arr[0][4]==1:
labels='Rotten Banana'
elif arr[0][5]==1:
labels='Rotten Oranges'

# Mengambil indeks kelas dengan nilai probabilitas tertinggi
predicted_class_index = np.argmax(arr)

# Daftar label yang sesuai dengan kelas
class_labels = [
'Fresh Apples', 'Fresh Banana', 'Fresh Cucumber', 'Fresh Okra',
'Fresh Oranges', 'Fresh Potato', 'Fresh Tomato', 'Fresh Carrot',
'Rotten Apples', 'Rotten Banana', 'Rotten Cucumber',
'Rotten Okra', 'Rotten Oranges', 'Rotten Potato', 'Rotten Tomato', 'Rotten Carrot'
]

# Menentukan label
predicted_label = class_labels[predicted_class_index]

return {"result":predicted_label}
return {"result":labels}
except Exception as e:
traceback.print_exc()
response.status_code = 500
Expand Down

0 comments on commit 374f5ee

Please sign in to comment.