ebgoldstein commited on
Commit
5bd98aa
·
verified ·
1 Parent(s): c169847

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
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
- # Convert the prediction to float32 for softmax calculation
42
- prediction = prediction.astype(np.float32)
43
-
44
- # Apply softmax to get probabilities
45
- probabilities = tf.nn.softmax(prediction[0]).numpy()
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=gr.Label(num_top_classes=2), # Outputs a label with the predicted classes
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