kkhushisaid commited on
Commit
de2b260
·
verified ·
1 Parent(s): 1d9d109

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -17,23 +17,25 @@ def preprocess_image(image):
17
 
18
  # Prediction function
19
  def predict(image):
20
- image_array = preprocess_image(image)
21
- prediction = model.predict(image_array)[0][0]
22
- label = "Pneumonia" if prediction > 0.5 else "Normal"
23
- confidence = prediction if prediction > 0.5 else 1 - prediction
24
- return f"{label} ({confidence * 100:.2f}% confidence)"
 
 
 
25
 
26
  # Gradio interface
27
  interface = gr.Interface(
28
  fn=predict,
29
- inputs=gr.Image(type="pil"),
30
- outputs="text",
31
- title="Pneumonia Detection from Chest X-rays",
32
- description="Upload a chest X-ray image to detect if the person has pneumonia.",
33
- theme="huggingface",
34
  allow_flagging="never"
35
  )
36
 
37
- # Launch the app
38
- if __name__ == "__main__":
39
- interface.launch()
 
17
 
18
  # Prediction function
19
  def predict(image):
20
+ try:
21
+ image_array = preprocess_image(image)
22
+ prediction = model.predict(image_array)[0][0]
23
+ label = "Pneumonia" if prediction > 0.5 else "Normal"
24
+ confidence = prediction if prediction > 0.5 else 1 - prediction
25
+ return f"{label} ({confidence * 100:.2f}% confidence)"
26
+ except Exception as e:
27
+ return f"Error: {str(e)}"
28
 
29
  # Gradio interface
30
  interface = gr.Interface(
31
  fn=predict,
32
+ inputs=gr.Image(type="pil", label="Upload Chest X-ray"),
33
+ outputs=gr.Textbox(label="Prediction"),
34
+ title="🫁 Pneumonia Detection from Chest X-rays",
35
+ description="Upload a chest X-ray image to detect if the person has pneumonia using a deep learning model.",
36
+ theme="default",
37
  allow_flagging="never"
38
  )
39
 
40
+ # Important: Always call launch() outside of __main__ block on Hugging Face Spaces
41
+ interface.launch(debug=True)