Update app.py
Browse files
app.py
CHANGED
|
@@ -118,25 +118,24 @@ if st.button("Predict"):
|
|
| 118 |
|
| 119 |
|
| 120 |
# Send a POST request to the FastAPI server
|
| 121 |
-
response = requests.post("
|
| 122 |
|
| 123 |
-
|
| 124 |
# Check if the request was successful
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
else:
|
| 135 |
-
st.error("This individual is predicted to have an income of under $50K")
|
| 136 |
-
|
| 137 |
-
# Display prediction probability
|
| 138 |
-
st.subheader("Prediction Probability")
|
| 139 |
-
probability = prediction_data['prediction_probability']
|
| 140 |
-
st.write(f"The probability of the individual having an income over $50K is: {probability:.2f}")
|
| 141 |
else:
|
| 142 |
-
st.error("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
# Send a POST request to the FastAPI server
|
| 121 |
+
response = requests.post("http://localhost:8000/predict/", json=user_input) # Use the correct URL
|
| 122 |
|
|
|
|
| 123 |
# Check if the request was successful
|
| 124 |
+
if response.status_code == 200:
|
| 125 |
+
prediction_data = response.json()
|
| 126 |
+
|
| 127 |
+
# Display prediction result to the user
|
| 128 |
+
st.subheader("Prediction Result")
|
| 129 |
+
|
| 130 |
+
# Determine income prediction and format message
|
| 131 |
+
if prediction_data['income_prediction'] == "Income over $50K":
|
| 132 |
+
st.success("This individual is predicted to have an income of over $50K.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
else:
|
| 134 |
+
st.error("This individual is predicted to have an income of under $50K")
|
| 135 |
+
|
| 136 |
+
# Display prediction probability
|
| 137 |
+
st.subheader("Prediction Probability")
|
| 138 |
+
probability = prediction_data['prediction_probability']
|
| 139 |
+
st.write(f"The probability of the individual having an income over $50K is: {probability:.2f}")
|
| 140 |
+
else:
|
| 141 |
+
st.error("Error: Unable to get prediction")
|