sunil18p31a0101 commited on
Commit
594af3a
·
verified ·
1 Parent(s): c5384a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -82,7 +82,7 @@ def extract_features(image_path):
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,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'] = Age
94
- features['Gender'] = 1 if Gender.lower() == 'male' else 0
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
- Hgb = svr_model.predict(features_df_scaled)[0]
104
 
105
- return f"Predicted Hemoglobin Value: {Hgb:.2f}"
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
- 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,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=[Age, Gender, image_input], outputs=output)
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