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 22, 2023
1 parent f1a7567 commit 04108cb
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ async def predict_image(img: UploadFile, response: Response):
# 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'

return {"result":labels}
arr = model.predict(image, batch_size=10)

# 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 Oranges',
'Rotten Apples', 'Rotten Banana', 'Rotten Cucumber',
'Rotten Oranges'
]

# Menentukan label
predicted_label = class_labels[predicted_class_index]

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

0 comments on commit 04108cb

Please sign in to comment.