sunil18p31a0101 commited on
Commit
6f3e953
·
verified ·
1 Parent(s): 1bd92fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -23
app.py CHANGED
@@ -84,11 +84,12 @@ def check_image_format(filepath):
84
  return False
85
 
86
  # Function to predict hemoglobin value
 
87
  def predict_hemoglobin(age, gender, image):
88
  try:
89
- # Check if the image file is valid
90
- if not check_image_format(image.name):
91
- return "Error: The uploaded image file is not recognized or is corrupt. Please upload an image in JPG, PNG, BMP, or GIF format."
92
 
93
  # Extract features from the image
94
  features = extract_features(image)
@@ -124,23 +125,3 @@ def predict_hemoglobin(age, gender, image):
124
  except Exception as e:
125
  print(f"An error occurred during prediction: {e}")
126
  return "An error occurred during prediction. Please try again."
127
-
128
- # Gradio Interface setup
129
- def create_gradio_interface():
130
- # Define the inputs and outputs for the Gradio interface
131
- image_input = gr.Image(type="pil", label="Image (Upload Image)", interactive=True)
132
- age_input = gr.Number(label="Age", value=25, precision=0)
133
- gender_input = gr.Radio(choices=["Male", "Female"], label="Gender", value="Male")
134
-
135
- # Set up the Gradio interface with the prediction function
136
- iface = gr.Interface(fn=predict_hemoglobin,
137
- inputs=[age_input, gender_input, image_input],
138
- outputs="text",
139
- live=True,
140
- title="Hemoglobin Prediction")
141
-
142
- iface.launch(share=True) # Set share=True to create a public link
143
-
144
- # Run the Gradio app
145
- if __name__ == "__main__":
146
- create_gradio_interface()
 
84
  return False
85
 
86
  # Function to predict hemoglobin value
87
+ # Updated predict_hemoglobin function
88
  def predict_hemoglobin(age, gender, image):
89
  try:
90
+ # Ensure the image is not None
91
+ if image is None:
92
+ return "Error: No image uploaded. Please upload an image."
93
 
94
  # Extract features from the image
95
  features = extract_features(image)
 
125
  except Exception as e:
126
  print(f"An error occurred during prediction: {e}")
127
  return "An error occurred during prediction. Please try again."