skavtech commited on
Commit
e7a1b6e
·
verified ·
1 Parent(s): 55c83c5

Application code

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -11,7 +11,7 @@ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
11
  model = tf.keras.models.load_model("maheshbabu.h5")
12
 
13
  # Define class labels
14
- classes = ["Normal","Cancerous"]
15
 
16
  # Prediction function
17
  def predict(image):
@@ -26,7 +26,12 @@ def predict(image):
26
  class_idx = np.argmax(predictions[0]) # Get index of highest probability
27
  confidence = predictions[0][class_idx] # Get confidence score
28
 
29
- return f"{classes[class_idx]} ({confidence:.2f})" # Return class and confidence
 
 
 
 
 
30
  except Exception as e:
31
  return f"Error processing image: {str(e)}"
32
 
@@ -34,10 +39,10 @@ def predict(image):
34
  interface = gr.Interface(
35
  fn=predict,
36
  inputs=gr.Image(type="filepath"), # Use filepath to pass the image path
37
- outputs="label",
38
  title="Blood Cancer Detection",
39
  description="Upload an image to detect whether it is Normal or Cancerous."
40
  )
41
 
42
  if __name__ == "__main__":
43
- interface.launch(server_port=7860, server_name="0.0.0.0", share=True)
 
11
  model = tf.keras.models.load_model("maheshbabu.h5")
12
 
13
  # Define class labels
14
+ classes = ["Normal", "Cancerous"]
15
 
16
  # Prediction function
17
  def predict(image):
 
26
  class_idx = np.argmax(predictions[0]) # Get index of highest probability
27
  confidence = predictions[0][class_idx] # Get confidence score
28
 
29
+ # Modify the output based on the prediction
30
+ if classes[class_idx] == "Normal":
31
+ return "No Cancer Found"
32
+ else:
33
+ return "Cancer Found!"
34
+
35
  except Exception as e:
36
  return f"Error processing image: {str(e)}"
37
 
 
39
  interface = gr.Interface(
40
  fn=predict,
41
  inputs=gr.Image(type="filepath"), # Use filepath to pass the image path
42
+ outputs="text", # Change output type to "text" for customized message
43
  title="Blood Cancer Detection",
44
  description="Upload an image to detect whether it is Normal or Cancerous."
45
  )
46
 
47
  if __name__ == "__main__":
48
+ interface.launch(server_port=7860, server_name="0.0.0.0", share=True)