Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import pickle
|
|
| 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,23 +62,14 @@ if __name__ == "__main__":
|
|
| 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 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 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()
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import streamlit as st
|
| 5 |
import requests
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 62 |
|
| 63 |
submit = st.button("Predict")
|
| 64 |
if submit:
|
| 65 |
+
payload = {"Sepal_Length": sepal_length, "Sepal_Width": sepal_width, "Petal_Length": petal_length, "Petal_Width": petal_width}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
prediction = st.empty()
|
| 67 |
with st.spinner("Predicting..."):
|
| 68 |
+
response = requests.post("http://localhost:8000/predict", json=payload)
|
| 69 |
+
if response.status_code == 200:
|
| 70 |
+
prediction_result = response.json()
|
| 71 |
+
prediction.success(f"Prediction: {prediction_result['prediction']}")
|
| 72 |
+
else:
|
| 73 |
+
prediction.error("Prediction failed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
uvicorn_proc.kill()
|