Update app.py
Browse files
app.py
CHANGED
|
@@ -114,34 +114,25 @@ if st.button("Predict"):
|
|
| 114 |
"importance_of_record": float(importance_of_record)
|
| 115 |
}
|
| 116 |
|
| 117 |
-
# Send a POST request to the FastAPI server
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
url.addheaders = [("Content-Type", "application/json")]
|
| 124 |
-
url.addheaders.append(("Accept", "application/json"))
|
| 125 |
-
request = urllib.request.Request(url)
|
| 126 |
-
request.data = json.dumps(user_input).encode("utf-8")
|
| 127 |
-
response = url.open(request)
|
| 128 |
-
|
| 129 |
-
# Check if the request was successful
|
| 130 |
-
if response.status == 200:
|
| 131 |
-
prediction_data = json.loads(response.read().decode("utf-8"))
|
| 132 |
|
| 133 |
# Display prediction result to the user
|
| 134 |
st.subheader("Prediction Result")
|
| 135 |
|
| 136 |
# Determine income prediction and format message
|
| 137 |
if prediction_data['income_prediction'] == "Income over $50K":
|
| 138 |
-
|
| 139 |
else:
|
| 140 |
-
|
| 141 |
|
| 142 |
# Display prediction probability
|
| 143 |
st.subheader("Prediction Probability")
|
| 144 |
probability = prediction_data['prediction_probability']
|
| 145 |
st.write(f"The probability of the individual having an income over $50K is: {probability:.2f}")
|
| 146 |
-
|
| 147 |
st.error("Error: Unable to get prediction")
|
|
|
|
| 114 |
"importance_of_record": float(importance_of_record)
|
| 115 |
}
|
| 116 |
|
| 117 |
+
# Send a POST request to the FastAPI server
|
| 118 |
+
response = requests.post("https://rasmodev-income-prediction-fastapi.hf.space/predict/", json=user_input, port=api_port)
|
| 119 |
|
| 120 |
+
# Check if the request was successful
|
| 121 |
+
if response.status_code == 200:
|
| 122 |
+
prediction_data = response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Display prediction result to the user
|
| 125 |
st.subheader("Prediction Result")
|
| 126 |
|
| 127 |
# Determine income prediction and format message
|
| 128 |
if prediction_data['income_prediction'] == "Income over $50K":
|
| 129 |
+
st.success("This individual is predicted to have an income of over $50K.")
|
| 130 |
else:
|
| 131 |
+
st.error("This individual is predicted to have an income of under $50K")
|
| 132 |
|
| 133 |
# Display prediction probability
|
| 134 |
st.subheader("Prediction Probability")
|
| 135 |
probability = prediction_data['prediction_probability']
|
| 136 |
st.write(f"The probability of the individual having an income over $50K is: {probability:.2f}")
|
| 137 |
+
else:
|
| 138 |
st.error("Error: Unable to get prediction")
|