AttributeError while deploying my app on streamlit

Hello Streamlit community,

I am trying to deploy laptop price prediction application, but I am facing the following issue while deploying it.
My app is running perfectly fine in local.

AttributeError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:
File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
    exec(code, module.__dict__)
File "/mount/src/laptop-price-predictor-deployed/app.py", line 54, in <module>
    pred = pipe.predict(inputs)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/pipeline.py", line 602, in predict
    Xt = transform.transform(Xt)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/utils/_set_output.py", line 295, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/compose/_column_transformer.py", line 1014, in transform
    Xs = self._call_func_on_transformers(
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/compose/_column_transformer.py", line 823, in _call_func_on_transformers
    return Parallel(n_jobs=self.n_jobs)(jobs)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/utils/parallel.py", line 67, in __call__
    return super().__call__(iterable_with_config)
File "/home/adminuser/venv/lib/python3.9/site-packages/joblib/parallel.py", line 1863, in __call__
    return output if self.return_generator else list(output)
File "/home/adminuser/venv/lib/python3.9/site-packages/joblib/parallel.py", line 1792, in _get_sequential_output
    res = func(*args, **kwargs)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/utils/parallel.py", line 129, in __call__
    return self.function(*args, **kwargs)
File "/home/adminuser/venv/lib/python3.9/site-packages/sklearn/pipeline.py", line 1283, in _transform_one
    res = transformer.transform(X, **params.transform)

This is my github repo: GitHub - rishabhprasad2003/Laptop-Price-Predictor-Deployed

URL for app(facing error while predicting): https://laptop-price-predictor-in-rupee.streamlit.app/

streamlit version : 1.32.0
python version : 3.11.5

hi @Rishabh_Prasad . I have seen your repo and tried for prediction. Here are the some things i noticed. You didn’t save the model in the proper way. Ill attach the proof at last. So go back to your notebook and the save the model as shown below:-

import joblib
df=joblib.dump('df.pkl')
pipe=joblib.dump('pipe.pkl')

#For loading the model you need to use as follows:-
df=joblib.load('df.pkl')
pipe=joblib.load('pipe.pkl')

Proof:-

Hope it works well !!

Happy Streamliting :balloon:

@Guna_Sekhar_Venkata thank for your precious time for helping me out in this situation.
I took your suggestion into considerations and also uploaded the df_joblib and pipe_joblib to my github repo.

Now I encountered a different problem, below is the error message.
It is working fine in local. But showing this error while deploying

@Rishabh_Prasad . You need updated requirements.txt file with new dependency named joblib. Don’t forget to reboot the application after updating the dependencies.

Hope it works well !!

Happy Streamlit-ing :balloon:

@Guna_Sekhar_Venkata thanks again for the solutions but still the error remains.
I checked the log while deploying the app and found the below error.
the module they are talking about is pandas.core.indexes.numeric but I have included pandas in my requirements.txt file

ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'
2024-03-11 17:14:27.210 503 GET /script-health-check (10.12.84.118) 176.80ms
2024-03-11 17:14:32.205 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/laptop-price-predictor-deployed/app.py", line 10, in <module>
    df = joblib.load("df_joblib.pkl")
  File "/home/adminuser/venv/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 658, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/home/adminuser/venv/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 577, in _unpickle
    obj = unpickler.load()
  File "/usr/local/lib/python3.9/pickle.py", line 1212, in load
    dispatch[key[0]](self)
  File "/usr/local/lib/python3.9/pickle.py", line 1537, in load_stack_global
    self.append(self.find_class(module, name))
  File "/usr/local/lib/python3.9/pickle.py", line 1579, in find_class
    __import__(module, level=0)

I found several related web pages in the Internets.

What is the python version you have used before deploying the app in the cloud?

@Guna_Sekhar_Venkata
I think thehe error might be occurring because the pipe object is expecting input data in a specific format, but the data provided is not matching that format.Ensure that the input array has the correct data types and shape (1, 13) as expected by the pipeline.

Yes.

I have checked his GitHub repo. He already done reshape before passing the input into predict function

I used python version: 3.11.5
and pandas version: 1.5.3
Is it something to do with pandas version?

I checked those websites and blog they say, Its something related to pandas version

Once degrade the python version to 3.10 and check it out.

Yes, it is because different versions of pandas. I don’t think you have pandas==1.5.3 in streamlit cloud.

I degraded my python version in my virtual env and updated all my .pkl files and app.py files.
rebooted my streamlit deploy, and It shows me below error in logs

AttributeError: 'str' object has no attribute 'transform'

I checked some posts and they are saying that they have fixed the pandas issue, so I dont think my version of pandas should conflict with my streamlit version

That is not your issue.

Hey have you checked with your pickle files in colab notebook before building the app? I’m not sure may be those pickle files have some error


I have verified my pickle files and dont know what is wrong. I app is working fine in local its all the deployment issue.

@Rishabh_Prasad i mean once use pipe.pkl for prediction.