Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -62,20 +62,20 @@ if st.button("Predict Customer Conversion"):
|
|
| 62 |
"https://manasranjanpani-extraalearncustomerpredictionbackend.hf.space/v1/customers",
|
| 63 |
json=input_data
|
| 64 |
)
|
| 65 |
-
|
| 66 |
if response.status_code == 200:
|
| 67 |
result = response.json()
|
| 68 |
prediction = result['Predicted_Sales']
|
| 69 |
st.success(f"Predicted Customer Conversion Score: {prediction:.2f}")
|
| 70 |
-
|
| 71 |
# Display additional info if available
|
| 72 |
if 'input_received' in result:
|
| 73 |
st.info(f"Processed {len(result['input_received']['fields_processed'])} features successfully")
|
| 74 |
-
|
| 75 |
else:
|
| 76 |
error_data = response.json()
|
| 77 |
st.error(f"Error making prediction: {error_data.get('error', 'Unknown error')}")
|
| 78 |
-
|
| 79 |
except requests.exceptions.RequestException as e:
|
| 80 |
st.error(f"Connection error: {e}")
|
| 81 |
except Exception as e:
|
|
@@ -92,11 +92,11 @@ if uploaded_file is not None:
|
|
| 92 |
st.write("Preview of uploaded data:")
|
| 93 |
batch_data = pd.read_csv(uploaded_file)
|
| 94 |
st.dataframe(batch_data.head())
|
| 95 |
-
|
| 96 |
# Check if required columns are present
|
| 97 |
required_columns = list(input_data.keys())
|
| 98 |
missing_columns = [col for col in required_columns if col not in batch_data.columns]
|
| 99 |
-
|
| 100 |
if missing_columns:
|
| 101 |
st.warning(f"Missing required columns in CSV: {missing_columns}")
|
| 102 |
st.info(f"Required columns: {required_columns}")
|
|
@@ -108,16 +108,16 @@ if uploaded_file is not None and st.button("Predict Batch"):
|
|
| 108 |
try:
|
| 109 |
# Reset file pointer to beginning
|
| 110 |
uploaded_file.seek(0)
|
| 111 |
-
|
| 112 |
response = requests.post(
|
| 113 |
"https://manasranjanpani-extraalearncustomerpredictionbackend.hf.space/v1/customersbatch",
|
| 114 |
files={"file": uploaded_file}
|
| 115 |
)
|
| 116 |
-
|
| 117 |
if response.status_code == 200:
|
| 118 |
predictions = response.json()
|
| 119 |
st.success("Batch predictions completed!")
|
| 120 |
-
|
| 121 |
# Display predictions in a nice format
|
| 122 |
if 'predictions' in predictions:
|
| 123 |
st.write("Predictions:")
|
|
@@ -127,11 +127,11 @@ if uploaded_file is not None and st.button("Predict Batch"):
|
|
| 127 |
# If predictions are keyed by ID
|
| 128 |
predictions_df = pd.DataFrame(list(predictions.items()), columns=['Customer ID', 'Prediction'])
|
| 129 |
st.dataframe(predictions_df)
|
| 130 |
-
|
| 131 |
else:
|
| 132 |
error_data = response.json()
|
| 133 |
st.error(f"Error making batch prediction: {error_data.get('error', 'Unknown error')}")
|
| 134 |
-
|
| 135 |
except requests.exceptions.RequestException as e:
|
| 136 |
st.error(f"Connection error: {e}")
|
| 137 |
except Exception as e:
|
|
@@ -182,7 +182,7 @@ st.download_button(
|
|
| 182 |
with st.expander("Required Fields Information"):
|
| 183 |
st.write("""
|
| 184 |
The following fields are required for prediction:
|
| 185 |
-
|
| 186 |
- **age**: Customer age (15-80)
|
| 187 |
- **currentOccupation**: Student, Unemployed, Employed, Self-Employed, Professional
|
| 188 |
- **firstInteraction**: How the customer first interacted with ExtraaLearn
|
|
|
|
| 62 |
"https://manasranjanpani-extraalearncustomerpredictionbackend.hf.space/v1/customers",
|
| 63 |
json=input_data
|
| 64 |
)
|
| 65 |
+
|
| 66 |
if response.status_code == 200:
|
| 67 |
result = response.json()
|
| 68 |
prediction = result['Predicted_Sales']
|
| 69 |
st.success(f"Predicted Customer Conversion Score: {prediction:.2f}")
|
| 70 |
+
|
| 71 |
# Display additional info if available
|
| 72 |
if 'input_received' in result:
|
| 73 |
st.info(f"Processed {len(result['input_received']['fields_processed'])} features successfully")
|
| 74 |
+
|
| 75 |
else:
|
| 76 |
error_data = response.json()
|
| 77 |
st.error(f"Error making prediction: {error_data.get('error', 'Unknown error')}")
|
| 78 |
+
|
| 79 |
except requests.exceptions.RequestException as e:
|
| 80 |
st.error(f"Connection error: {e}")
|
| 81 |
except Exception as e:
|
|
|
|
| 92 |
st.write("Preview of uploaded data:")
|
| 93 |
batch_data = pd.read_csv(uploaded_file)
|
| 94 |
st.dataframe(batch_data.head())
|
| 95 |
+
|
| 96 |
# Check if required columns are present
|
| 97 |
required_columns = list(input_data.keys())
|
| 98 |
missing_columns = [col for col in required_columns if col not in batch_data.columns]
|
| 99 |
+
|
| 100 |
if missing_columns:
|
| 101 |
st.warning(f"Missing required columns in CSV: {missing_columns}")
|
| 102 |
st.info(f"Required columns: {required_columns}")
|
|
|
|
| 108 |
try:
|
| 109 |
# Reset file pointer to beginning
|
| 110 |
uploaded_file.seek(0)
|
| 111 |
+
|
| 112 |
response = requests.post(
|
| 113 |
"https://manasranjanpani-extraalearncustomerpredictionbackend.hf.space/v1/customersbatch",
|
| 114 |
files={"file": uploaded_file}
|
| 115 |
)
|
| 116 |
+
|
| 117 |
if response.status_code == 200:
|
| 118 |
predictions = response.json()
|
| 119 |
st.success("Batch predictions completed!")
|
| 120 |
+
|
| 121 |
# Display predictions in a nice format
|
| 122 |
if 'predictions' in predictions:
|
| 123 |
st.write("Predictions:")
|
|
|
|
| 127 |
# If predictions are keyed by ID
|
| 128 |
predictions_df = pd.DataFrame(list(predictions.items()), columns=['Customer ID', 'Prediction'])
|
| 129 |
st.dataframe(predictions_df)
|
| 130 |
+
|
| 131 |
else:
|
| 132 |
error_data = response.json()
|
| 133 |
st.error(f"Error making batch prediction: {error_data.get('error', 'Unknown error')}")
|
| 134 |
+
|
| 135 |
except requests.exceptions.RequestException as e:
|
| 136 |
st.error(f"Connection error: {e}")
|
| 137 |
except Exception as e:
|
|
|
|
| 182 |
with st.expander("Required Fields Information"):
|
| 183 |
st.write("""
|
| 184 |
The following fields are required for prediction:
|
| 185 |
+
|
| 186 |
- **age**: Customer age (15-80)
|
| 187 |
- **currentOccupation**: Student, Unemployed, Employed, Self-Employed, Professional
|
| 188 |
- **firstInteraction**: How the customer first interacted with ExtraaLearn
|