Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +14 -9
src/streamlit_app.py
CHANGED
|
@@ -12,8 +12,8 @@ product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1,
|
|
| 12 |
product_sugar = st.selectbox("Product Sugar Content", [0, 1])
|
| 13 |
product_alloc_area = st.number_input("Allocated Display Area (sq. m)", min_value=0.0, step=0.01, value=0.05)
|
| 14 |
product_mrp = st.number_input("Product MRP", min_value=1.0, step=0.5, value=150.0)
|
| 15 |
-
store_size = st.selectbox("Store Size", [0, 1, 2])
|
| 16 |
-
store_city_type = st.selectbox("Store Location City Type", [0, 1, 2])
|
| 17 |
store_type = st.selectbox("Store Type", [0, 1, 2, 3])
|
| 18 |
store_age = st.slider("Store Age (Years)", 0, 30, 10)
|
| 19 |
|
|
@@ -51,18 +51,23 @@ 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 |
result = response.json()
|
| 59 |
-
prediction = result.get("prediction"
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
st.error(f"β API Error: Status code {response.status_code}")
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
st.error(f"β Request failed: {e}")
|
|
|
|
| 12 |
product_sugar = st.selectbox("Product Sugar Content", [0, 1])
|
| 13 |
product_alloc_area = st.number_input("Allocated Display Area (sq. m)", min_value=0.0, step=0.01, value=0.05)
|
| 14 |
product_mrp = st.number_input("Product MRP", min_value=1.0, step=0.5, value=150.0)
|
| 15 |
+
store_size = st.selectbox("Store Size", [0, 1, 2])
|
| 16 |
+
store_city_type = st.selectbox("Store Location City Type", [0, 1, 2])
|
| 17 |
store_type = st.selectbox("Store Type", [0, 1, 2, 3])
|
| 18 |
store_age = st.slider("Store Age (Years)", 0, 30, 10)
|
| 19 |
|
|
|
|
| 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 |
result = response.json()
|
| 59 |
+
prediction = result.get("prediction")
|
| 60 |
+
|
| 61 |
+
if prediction is not None:
|
| 62 |
+
try:
|
| 63 |
+
prediction = float(prediction)
|
| 64 |
+
st.success(f"β
Predicted Sales: **{prediction:.2f} units**")
|
| 65 |
+
except (ValueError, TypeError):
|
| 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(f"Response: {response.text}")
|
| 72 |
except Exception as e:
|
| 73 |
st.error(f"β Request failed: {e}")
|