Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -12
src/streamlit_app.py
CHANGED
|
@@ -51,23 +51,24 @@ if st.button("Predict Sales"):
|
|
| 51 |
with st.spinner("Fetching prediction from backend..."):
|
| 52 |
try:
|
| 53 |
response = requests.post(
|
| 54 |
-
"https://lokiiparihar-
|
| 55 |
json=input_data
|
| 56 |
)
|
| 57 |
if response.status_code == 200:
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
st.error(f"β Prediction format error: {prediction}")
|
| 67 |
-
else:
|
| 68 |
-
st.error("β Prediction not returned by backend.")
|
| 69 |
else:
|
| 70 |
st.error(f"β API Error: Status code {response.status_code}")
|
| 71 |
-
st.text(
|
| 72 |
except Exception as e:
|
| 73 |
st.error(f"β Request failed: {e}")
|
|
|
|
| 51 |
with st.spinner("Fetching prediction from backend..."):
|
| 52 |
try:
|
| 53 |
response = requests.post(
|
| 54 |
+
"https://lokiiparihar-SuperkartBackendModalDeploy-XGBoost.hf.space/predict",
|
| 55 |
json=input_data
|
| 56 |
)
|
| 57 |
if response.status_code == 200:
|
| 58 |
+
try:
|
| 59 |
+
result = response.json()
|
| 60 |
+
prediction = result.get("prediction", None)
|
| 61 |
+
except ValueError:
|
| 62 |
+
# Handle raw text response
|
| 63 |
+
prediction = response.text
|
| 64 |
|
| 65 |
+
try:
|
| 66 |
+
prediction = float(prediction)
|
| 67 |
+
st.success(f"β
Predicted Sales: **{prediction:.2f} units**")
|
| 68 |
+
except (ValueError, TypeError):
|
| 69 |
+
st.error(f"β Could not convert prediction to number: {prediction}")
|
|
|
|
|
|
|
|
|
|
| 70 |
else:
|
| 71 |
st.error(f"β API Error: Status code {response.status_code}")
|
| 72 |
+
st.text(response.text)
|
| 73 |
except Exception as e:
|
| 74 |
st.error(f"β Request failed: {e}")
|