Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pickle
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import streamlit as st
|
| 5 |
import requests
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -62,14 +63,23 @@ if __name__ == "__main__":
|
|
| 62 |
|
| 63 |
submit = st.button("Predict")
|
| 64 |
if submit:
|
| 65 |
-
payload = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
prediction = st.empty()
|
| 67 |
with st.spinner("Predicting..."):
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
uvicorn_proc.kill()
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import streamlit as st
|
| 5 |
import requests
|
| 6 |
+
from requests.exceptions import ConnectionError
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
|
|
|
|
| 63 |
|
| 64 |
submit = st.button("Predict")
|
| 65 |
if submit:
|
| 66 |
+
payload = {
|
| 67 |
+
"Sepal_Length": sepal_length,
|
| 68 |
+
"Sepal_Width": sepal_width,
|
| 69 |
+
"Petal_Length": petal_length,
|
| 70 |
+
"Petal_Width": petal_width
|
| 71 |
+
}
|
| 72 |
prediction = st.empty()
|
| 73 |
with st.spinner("Predicting..."):
|
| 74 |
+
try:
|
| 75 |
+
response = requests.post("http://localhost:8000/predict", json=payload)
|
| 76 |
+
if response.status_code == 200:
|
| 77 |
+
prediction_result = response.json()
|
| 78 |
+
prediction.success(f"Prediction: {prediction_result['prediction']}")
|
| 79 |
+
else:
|
| 80 |
+
prediction.error("Prediction failed.")
|
| 81 |
+
except ConnectionError as e:
|
| 82 |
+
prediction.error("Failed to connect to the server. Make sure the FastAPI server is running.")
|
| 83 |
+
print(str(e))
|
| 84 |
|
| 85 |
uvicorn_proc.kill()
|