Spaces:
Build error
Build error
cutoff
Browse files
app.py
CHANGED
|
@@ -33,36 +33,42 @@ def parse_args(args):
|
|
| 33 |
|
| 34 |
# Inference function
|
| 35 |
def classify(tabular_data):
|
|
|
|
| 36 |
try:
|
| 37 |
# Ensure tabular_data is a 2D list and extract the first row
|
| 38 |
if isinstance(tabular_data, list) and isinstance(tabular_data[0], list):
|
| 39 |
-
tabular_data = tabular_data[0]
|
| 40 |
else:
|
| 41 |
raise ValueError("Input data is not in the expected 2D list format.")
|
| 42 |
-
|
| 43 |
# Convert input data to a pandas DataFrame
|
| 44 |
input_data = pd.DataFrame([tabular_data], columns= tabular_header)
|
| 45 |
print(f"Original Input DataFrame:\n{input_data}")
|
| 46 |
-
|
| 47 |
# Use PyCaret's predict_model to make predictions
|
| 48 |
prediction = predict_model(model, data=input_data)
|
| 49 |
-
|
| 50 |
# Extract predicted class and probability
|
| 51 |
predicted_class = prediction.loc[0, "prediction_label"]
|
| 52 |
class_probability = prediction.loc[0, "prediction_score"]
|
| 53 |
|
| 54 |
-
# Generate appropriate output based on the prediction
|
| 55 |
-
if
|
| 56 |
result = (
|
| 57 |
-
f"
|
| 58 |
-
|
| 59 |
)
|
| 60 |
-
|
| 61 |
result = (
|
| 62 |
-
f"
|
| 63 |
-
"
|
| 64 |
)
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
return result
|
| 67 |
|
| 68 |
except Exception as e:
|
|
|
|
| 33 |
|
| 34 |
# Inference function
|
| 35 |
def classify(tabular_data):
|
| 36 |
+
|
| 37 |
try:
|
| 38 |
# Ensure tabular_data is a 2D list and extract the first row
|
| 39 |
if isinstance(tabular_data, list) and isinstance(tabular_data[0], list):
|
| 40 |
+
tabular_data = tabular_data[0] # Extract the first row
|
| 41 |
else:
|
| 42 |
raise ValueError("Input data is not in the expected 2D list format.")
|
| 43 |
+
|
| 44 |
# Convert input data to a pandas DataFrame
|
| 45 |
input_data = pd.DataFrame([tabular_data], columns= tabular_header)
|
| 46 |
print(f"Original Input DataFrame:\n{input_data}")
|
| 47 |
+
|
| 48 |
# Use PyCaret's predict_model to make predictions
|
| 49 |
prediction = predict_model(model, data=input_data)
|
| 50 |
+
|
| 51 |
# Extract predicted class and probability
|
| 52 |
predicted_class = prediction.loc[0, "prediction_label"]
|
| 53 |
class_probability = prediction.loc[0, "prediction_score"]
|
| 54 |
|
| 55 |
+
# Generate appropriate output based on the prediction and probability
|
| 56 |
+
if class_probability < 0.34:
|
| 57 |
result = (
|
| 58 |
+
f"This analysis estimates a low probability ({class_probability:.2f}) of a common bile duct stone. "
|
| 59 |
+
"Please consult a medical professional for final diagnosis."
|
| 60 |
)
|
| 61 |
+
elif 0.34 <= class_probability < 0.67:
|
| 62 |
result = (
|
| 63 |
+
f"Based on the provided data, this tool estimates an intermediate probability ({class_probability:.2f}) "
|
| 64 |
+
"of a common bile duct stone. Further medical review is recommended."
|
| 65 |
)
|
| 66 |
+
else: # class_probability >= 0.67
|
| 67 |
+
result = (
|
| 68 |
+
f"Based on the provided data, this tool estimates a high probability ({class_probability:.2f}) "
|
| 69 |
+
"of a common bile duct stone. Further medical review is necessary."
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
return result
|
| 73 |
|
| 74 |
except Exception as e:
|