Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -82,7 +82,7 @@ def extract_features(image_path):
|
|
82 |
}
|
83 |
|
84 |
# Function to make predictions
|
85 |
-
def predict_hemoglobin(
|
86 |
print(f"Image path: {image}") # Debugging line to check the image path
|
87 |
|
88 |
# Check if the image file is valid
|
@@ -90,8 +90,8 @@ def predict_hemoglobin(Age, Gender, image):
|
|
90 |
return "Error: The uploaded image file is not recognized or is corrupt."
|
91 |
|
92 |
features = extract_features(image)
|
93 |
-
features['Age'] =
|
94 |
-
features['Gender'] = 1 if
|
95 |
features_df = pd.DataFrame([features])
|
96 |
|
97 |
# Load models
|
@@ -100,9 +100,9 @@ def predict_hemoglobin(Age, Gender, image):
|
|
100 |
label_encoder = joblib.load('label_encoder.pkl')
|
101 |
|
102 |
features_df_scaled = scaler.transform(features_df)
|
103 |
-
|
104 |
|
105 |
-
return f"Predicted Hemoglobin Value: {
|
106 |
|
107 |
# Gradio Interface
|
108 |
def gradio_interface():
|
@@ -110,8 +110,8 @@ def gradio_interface():
|
|
110 |
gr.Markdown("## Hemoglobin Prediction from Image Features")
|
111 |
|
112 |
with gr.Row():
|
113 |
-
|
114 |
-
|
115 |
|
116 |
image_input = gr.Image(type="filepath", label="Upload Image (Path to Image)", interactive=True)
|
117 |
|
@@ -120,7 +120,7 @@ def gradio_interface():
|
|
120 |
# Prediction button
|
121 |
predict_btn = gr.Button("Predict Hemoglobin")
|
122 |
|
123 |
-
predict_btn.click(fn=predict_hemoglobin, inputs=[
|
124 |
|
125 |
return demo
|
126 |
|
|
|
82 |
}
|
83 |
|
84 |
# Function to make predictions
|
85 |
+
def predict_hemoglobin(age, gender, image):
|
86 |
print(f"Image path: {image}") # Debugging line to check the image path
|
87 |
|
88 |
# Check if the image file is valid
|
|
|
90 |
return "Error: The uploaded image file is not recognized or is corrupt."
|
91 |
|
92 |
features = extract_features(image)
|
93 |
+
features['Age'] = age
|
94 |
+
features['Gender'] = 1 if gender.lower() == 'male' else 0
|
95 |
features_df = pd.DataFrame([features])
|
96 |
|
97 |
# Load models
|
|
|
100 |
label_encoder = joblib.load('label_encoder.pkl')
|
101 |
|
102 |
features_df_scaled = scaler.transform(features_df)
|
103 |
+
hemoglobin = svr_model.predict(features_df_scaled)[0]
|
104 |
|
105 |
+
return f"Predicted Hemoglobin Value: {hemoglobin:.2f}"
|
106 |
|
107 |
# Gradio Interface
|
108 |
def gradio_interface():
|
|
|
110 |
gr.Markdown("## Hemoglobin Prediction from Image Features")
|
111 |
|
112 |
with gr.Row():
|
113 |
+
age = gr.Number(label="Age", value=25)
|
114 |
+
gender = gr.Dropdown(choices=["Male", "Female"], label="Gender", value="Male")
|
115 |
|
116 |
image_input = gr.Image(type="filepath", label="Upload Image (Path to Image)", interactive=True)
|
117 |
|
|
|
120 |
# Prediction button
|
121 |
predict_btn = gr.Button("Predict Hemoglobin")
|
122 |
|
123 |
+
predict_btn.click(fn=predict_hemoglobin, inputs=[age, gender, image_input], outputs=output)
|
124 |
|
125 |
return demo
|
126 |
|