Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,24 +38,17 @@ def predict(image):
|
|
| 38 |
preprocessed_image = preprocess_image(image)
|
| 39 |
prediction = run_inference(interpreter, preprocessed_image)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
prediction
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Get class probabilities for Flood and NoFlood
|
| 48 |
-
flood_prob = probabilities[0]
|
| 49 |
-
no_flood_prob = probabilities[1]
|
| 50 |
-
|
| 51 |
-
# Return the predicted label along with probabilities
|
| 52 |
-
return {"Flood": float(flood_prob), "NoFlood": float(no_flood_prob)}
|
| 53 |
|
| 54 |
# Create Gradio interface
|
| 55 |
interface = gr.Interface(
|
| 56 |
fn=predict, # Function that runs the model
|
| 57 |
inputs=gr.Image(type="pil"), # Input is an image, processed as PIL image
|
| 58 |
-
outputs=
|
| 59 |
)
|
| 60 |
|
| 61 |
# Launch the app
|
|
|
|
| 38 |
preprocessed_image = preprocess_image(image)
|
| 39 |
prediction = run_inference(interpreter, preprocessed_image)
|
| 40 |
|
| 41 |
+
# Get the predicted class by comparing the output values
|
| 42 |
+
if prediction[0][0] > prediction[0][1]:
|
| 43 |
+
return "Flood"
|
| 44 |
+
else:
|
| 45 |
+
return "No Flood"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Create Gradio interface
|
| 48 |
interface = gr.Interface(
|
| 49 |
fn=predict, # Function that runs the model
|
| 50 |
inputs=gr.Image(type="pil"), # Input is an image, processed as PIL image
|
| 51 |
+
outputs="text", # Output is text indicating Flood or NoFlood
|
| 52 |
)
|
| 53 |
|
| 54 |
# Launch the app
|