if st.button('Predict Churn'):
# Prepare the data for the model
data = pd.DataFrame({
'Age': [10], # Use a list with a single value
'Gender': ['Male'], # Use a list with a single value
'Location': ['Los Angeles'], # Use a list with a single value
'Subscription_Length_Months': [5], # Use a list with a single value
'Monthly_Bill': [100], # Use a list with a single value
'Total_Usage_GB': [100] # Use a list with a single value
})
# Calling prediction pipeline to predict the output
predictor = ModelPrediction()
x = predictor.prediction(data)
# Return the prediction
st.subheader('Churn Prediction:')
if x < 0.5:
st.write('The customer is likely to stay (Churn: No)')
else:
st.write('The customer is likely to churn (Churn: Yes)')
The function i am calling will load a model and then input the given data to get an output, but i am when i do so it gives many error, i tried running it outside streamlit app and it works fine please hel.
CustomException: Error occurred python script name [C:\D_Drive\WORKS\Github_projects\customer_churn\src\pipelines\predict_pipeline.py] line number [21] error message [Error occurred python script name [C:\D_Drive\WORKS\Github_projects\customer_churn\src\utils\main_utils.py] line number [67] error message [[Errno 2] No such file or directory: โโฆ\โฆ\artifacts\model.pklโ]]
Traceback:
File "C:\Users\SAMAR\anaconda3\envs\CCP\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script
exec(code, module.__dict__)File "C:\D_Drive\WORKS\Github_projects\customer_churn\app.py", line 133, in <module>
x = predictor.prediction(data)
^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\D_Drive\WORKS\Github_projects\customer_churn\src\pipelines\predict_pipeline.py", line 54, in prediction
raise CustomException(e, sys) #type:ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It seems like the path youโre storing in model_pkl_path isnโt the correct path to the model.pkl file โ I was able to resolve the error by setting model_pkl_path to be the full path to the model.pkl file (in my case, just my local path to where the app is stored on my computer + \Customer_Churn_Prediction/artifacts/model.pkl).
Iโd recommend printing the value of model_pkl_path and playing around until the generated path matches what youโd expect given the location of the file. You could still generate the filepath rather than hard-coding it, but the path generated when I ran the app was ../../artifacts/model.pkl, which I think would take you to the parent directory above where the Streamlit app is running, and then the parent directory above that, and artifacts wouldnโt be in that folder.
Hope that makes sense! Let me know if you have any questions
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking โAccept allโ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.