FileNotFoundError: [Errno 2] No such file or directory (file_uploader)

Hi,

I’m trying deploying my first streamlit app.
I want to use the pycaret library to load pre-trained models into the app to forecast new data.
However, it fails to load the model (pkl) file and gives me the following error and I don’t know why

All Code below


import streamlit as st
import numpy as np
import pandas as pd

def convert_df(df):
   return df.to_csv(index=False).encode('shift-jis')

def predict(loaded_model, df):
    pred_holdout = predict_model(loaded_model, data=df)
    
    plot_model(loaded_model, plot='residuals', display_format='streamlit')
    plot_model(loaded_model, plot='feature', display_format='streamlit')
    plot_model(loaded_model, plot='error', display_format='streamlit')

    st.markdown("#### output the result as prediction_label")
    st.dataframe(pred_holdout, height=200)
    csv = convert_df(pred_holdout)
    st.download_button(
            "Download result",
            csv,
            "predict.csv",
            "text/csv",
            key='download-csv'
            )
    return pred_holdout

st.markdown("# AutoML Tool")

#st.sidebar.markdown("import the data")
uploaded_file = st.sidebar.file_uploader("import the data", type='csv', key='train')

if uploaded_file is not None:
    df = pd.read_csv(uploaded_file, encoding="shift-jis")
    st.markdown("#### 1. check the data")
    st.dataframe(df.head(10))

    st.markdown("### 2. select the method")
    ml_usecase = st.selectbox(label='regression or classification',
                            options=('', 'regression', 'classification'),
                            key='ml_usecase')
    if ml_usecase == 'regression':
        from pycaret.regression import *
    elif ml_usecase == 'classification':
        from pycaret.classification import *

    pkl_file = st.file_uploader("import model", type=".pkl", accept_multiple_files=False)

    if pkl_file is not None:
        loaded_model = load_model(pkl_file)
        target = st.selectbox(label='input objective variable', options=df.keys())
        ml = setup(data=df,
                    target=target,
            )
            
        predict(loaded_model, df)

It seems like you are using functions from the pycaret library, but you haven’t imported them at the beginning of your script. Specifically, the predict_model, plot_model, and setup functions are not imported.

To fix this, add the following imports at the beginning of your script:

python

from pycaret.regression import predict_model, plot_model, setup
from pycaret.classification import predict_model, plot_model, setup

Also, make sure that you have the pycaret library installed. You can install it using:

bash

pip install pycaret

After adding the necessary imports, your script should work correctly with the pycaret functions.

hope this fix your issue if not plz link donw your github repo or deployed link !
thank you !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.