Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -37,6 +37,18 @@ input_data = pd.DataFrame({
|
|
| 37 |
"Product_Type": Product_Type
|
| 38 |
}, index=[0])
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Make prediction when the "Predict" button is clicked
|
| 41 |
if st.button("Predict"):
|
| 42 |
response = requests.post("https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict", json=input_data.to_dict(orient="records")[0])
|
|
|
|
| 37 |
"Product_Type": Product_Type
|
| 38 |
}, index=[0])
|
| 39 |
|
| 40 |
+
def predict_sales(input_data):
|
| 41 |
+
backend_url = "https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict" # THIS LINE IS CRUCIAL
|
| 42 |
+
headers = {'Content-Type': 'application/json'}
|
| 43 |
+
try:
|
| 44 |
+
response = requests.post(backend_url, json=input_data, headers=headers)
|
| 45 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 46 |
+
prediction = response.json()['Predicted sales']
|
| 47 |
+
return prediction
|
| 48 |
+
except requests.exceptions.RequestException as e:
|
| 49 |
+
st.error(f"Error communicating with backend: {e}")
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
# Make prediction when the "Predict" button is clicked
|
| 53 |
if st.button("Predict"):
|
| 54 |
response = requests.post("https://MBG0903-SuperKartSalesPredictionBackend.hf.space/v1/predict", json=input_data.to_dict(orient="records")[0])
|