Lokiiparihar commited on
Commit
c0232cb
Β·
verified Β·
1 Parent(s): 0cbcad5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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-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}")
 
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}")