Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
90 |
-
if
|
91 |
-
return "Error:
|
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."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|