Machine Learning Model After Deployed on Streamlit Coumminity Cloud is Giving Wrong Prediction

I created a spam prediction machine learning model and for creating an interface i went to pycharm and wrote app.py code and there are two other files which is vectorizer.pkl and model.pkl used in the app.py file and on terminal i wrote streamlit run app.py and it took me to the local host 8501 browser, now everything worked fine it made right predictions. I wanted to make this app public to share the link on github. I went to streamlit community cloud made an account linked it with my github and deployed the app. The github respo has all the necessary file including the notebook with the whole ml model, app.py, model.pkl,requirements.txt, vectorizer.pkl. now the problem is the app deployed using the public link is giving a different prediction( that is it is saying Not Spam instead of saying Spam) for the exact same input. I’m attaching the output here please tell me what to do.

github link : Spam-Gaurd/app.py at main Β· ardra1111/Spam-Gaurd Β· GitHub
streamlit cloud app link: https://spam-gaurd-ir5t9kbcsjpdkus4cveywj.streamlit.app/

attaching images of local host 8051 and stream lit community cloud deployed:


1 Like

Hi @Ardra_Ajay . Once check in the cloud that what the variable named result is giving. May be it’s returning some thing that’s why it’s directly going to else part .
Happy Streamlit-ing :balloon:

1 Like

This is what’s being shown when I click the manage app

[     UTC     ] Logs for spam-gaurd-ardra1111.streamlit.app/
────────────────────────────────────────────────────────────────────────────────────────
[12:29:00] πŸš€ Starting up repository: 'spam-gaurd', branch: 'main', main module: 'app.py'
[12:29:00] πŸ™ Cloning repository...
[12:29:02] πŸ™ Cloning into '/mount/src/spam-gaurd'...
Warning: Permanently added the ED25519 host key for IP address '192.30.255.112' to the list of known hosts.
[12:29:02] πŸ™ Cloned repository!
[12:29:02] πŸ™ Pulling code changes from Github...
[12:29:03] πŸ“¦ Processing dependencies...

──────────────────────────────────────── pip ───────────────────────────────────────────

Collecting streamlit
  Downloading streamlit-1.31.0-py2.py3-none-any.whl (8.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 130.5 MB/s eta 0:00:00[2024-02-05 12:29:04.596352] 
Collecting scikit-learn
  Downloading scikit_learn-1.4.0-1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.1/12.1 MB 222.2 MB/s eta 0:00:00[2024-02-05 12:29:04.908833] 
Collecting nltk
  Downloading nltk-3.8.1-py3-none-any.whl (1.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 201.7 MB/s eta 0:00:00[2024-02-05 12:29:05.017476] 
Collecting cachetools<6,>=4.0
  Downloading cachetools-5.3.2-py3-none-any.whl (9.3 kB)
Collecting packaging<24,>=16.8
  Downloading packaging-23.2-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 KB 106.5 MB/s eta 0:00:00[2024-02-05 12:29:05.203622] 
Collecting validators<1,>=0.2
  Downloading validators-0.22.0-py3-none-any.whl (26 kB)
Collecting pillow<11,>=7.1.0
  Downloading pillow-10.2.0-cp39-cp39-manylinux_2_28_x86_64.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 172.6 MB/s eta 0:00:00[2024-02-05 12:29:05.929543] 
Collecting watchdog>=2.1.5
  Downloading watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.1/82.1 KB 208.7 MB/s eta 0:00:00[2024-02-05 12:29:06.122067] 
Collecting pyarrow>=7.0
  Downloading pyarrow-15.0.0-cp39-cp39-manylinux_2_28_x86_64.whl (38.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.3/38.3 MB 139.9 MB/s eta 0:00:00[2024-02-05 12:29:06.685128] 
Collecting importlib-metadata<8,>=1.4
  Downloading importlib_metadata-7.0.1-py3-none-any.whl (23 kB)
Collecting numpy<2,>=1.19.3
  Downloading numpy-1.26.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 268.4 MB/s eta 0:00:00[2024-02-05 12:29:07.602155] 
Collecting typing-extensions<5,>=4.3.0
  Downloading typing_extensions-4.9.0-py3-none-any.whl (32 kB)
Collecting protobuf<5,>=3.20
  Downloading protobuf-4.25.2-cp37-abi3-manylinux2014_x86_64.whl (294 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 294.6/294.6 KB 121.7 MB/s eta 0:00:00[2024-02-05 12:29:08.448636] 
Collecting toml<2,>=0.10.1
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting blinker<2,>=1.0.0
  Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Collecting click<9,>=7.0
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 KB 142.8 MB/s eta 0:00:00[2024-02-05 12:29:08.595981] 
Collecting pydeck<1,>=0.8.0b4
  Downloading pydeck-0.8.1b0-py2.py3-none-any.whl (4.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.8/4.8 MB 153.5 MB/s eta 0:00:00[2024-02-05 12:29:08.689900] 
Collecting tzlocal<6,>=1.1
  Downloading tzlocal-5.2-py3-none-any.whl (17 kB)
Collecting rich<14,>=10.14.0
  Downloading rich-13.7.0-py3-none-any.whl (240 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 KB 243.3 MB/s eta 0:00:00[2024-02-05 12:29:08.878551] 
Collecting gitpython!=3.1.19,<4,>=3.0.7
  Downloading GitPython-3.1.41-py3-none-any.whl (196 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 196.4/196.4 KB 214.0 MB/s eta 0:00:00[2024-02-05 12:29:08.963104] 
Collecting pandas<3,>=1.3.0
  Downloading pandas-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.0/13.0 MB 267.5 MB/s eta 0:00:00[2024-02-05 12:29:09.331894] 
Collecting python-dateutil<3,>=2.7.3
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 257.1 MB/s eta 0:00:00[2024-02-05 12:29:09.395514] 
Collecting tornado<7,>=6.0.3
  Downloading tornado-6.4-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (435 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 435.4/435.4 KB 254.7 MB/s eta 0:00:00[2024-02-05 12:29:09.501620] 
Collecting altair<6,>=4.0
  Downloading altair-5.2.0-py3-none-any.whl (996 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 996.9/996.9 KB 277.2 MB/s eta 0:00:00[2024-02-05 12:29:09.553186] 
Collecting tenacity<9,>=8.1.0
  Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)
Collecting requests<3,>=2.27
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 135.6 MB/s eta 0:00:00[2024-02-05 12:29:09.670753] 
Collecting scipy>=1.6.0
  Downloading scipy-1.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.5/38.5 MB 148.5 MB/s eta 0:00:00[2024-02-05 12:29:10.232646] 
Collecting joblib>=1.2.0
  Downloading joblib-1.3.2-py3-none-any.whl (302 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 302.2/302.2 KB 140.7 MB/s eta 0:00:00
Collecting threadpoolctl>=2.0.0
  Downloading threadpoolctl-3.2.0-py3-none-any.whl (15 kB)
Collecting tqdm
  Downloading tqdm-4.66.1-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 KB 116.2 MB/s eta 0:00:00[2024-02-05 12:29:10.636915] 
Collecting regex>=2021.8.3
  Downloading regex-2023.12.25-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (773 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 773.4/773.4 KB 142.4 MB/s eta 0:00:00
Collecting toolz
  Downloading toolz-0.12.1-py3-none-any.whl (56 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.1/56.1 KB 116.0 MB/s eta 0:00:00[2024-02-05 12:29:11.941409] 
Collecting jinja2
  Downloading Jinja2-3.1.3-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.2/133.2 KB 128.9 MB/s eta 0:00:00[2024-02-05 12:29:12.050651] 
Collecting jsonschema>=3.0
  Downloading jsonschema-4.21.1-py3-none-any.whl (85 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.5/85.5 KB 65.3 MB/s eta 0:00:00[2024-02-05 12:29:12.177323] 
Collecting gitdb<5,>=4.0.1
  Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 KB 200.3 MB/s eta 0:00:00[2024-02-05 12:29:12.264137] 
Collecting zipp>=0.5
  Downloading zipp-3.17.0-py3-none-any.whl (7.4 kB)
Collecting pytz>=2020.1
  Downloading pytz-2024.1-py2.py3-none-any.whl (505 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 505.5/505.5 KB 154.9 MB/s eta 0:00:00[2024-02-05 12:29:12.557142] 
Collecting tzdata>=2022.7
  Downloading tzdata-2023.4-py2.py3-none-any.whl (346 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 346.6/346.6 KB 134.0 MB/s eta 0:00:00[2024-02-05 12:29:12.628769] 
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.6-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.6/61.6 KB 160.8 MB/s eta 0:00:00[2024-02-05 12:29:12.873272] 
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.2.0-py3-none-any.whl (120 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 120.9/120.9 KB 125.1 MB/s eta 0:00:00[2024-02-05 12:29:12.989862] 
Collecting certifi>=2017.4.17
  Downloading certifi-2024.2.2-py3-none-any.whl (163 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.8/163.8 KB 137.9 MB/s eta 0:00:00[2024-02-05 12:29:13.072290] 
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.3/142.3 KB 224.7 MB/s eta 0:00:00[2024-02-05 12:29:13.415268] 
Collecting markdown-it-py>=2.2.0
  Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 KB 162.6 MB/s eta 0:00:00[2024-02-05 12:29:13.477213] 
Collecting pygments<3.0.0,>=2.13.0
  Downloading pygments-2.17.2-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 269.6 MB/s eta 0:00:00[2024-02-05 12:29:13.545382] 
Collecting smmap<6,>=3.0.1
  Downloading smmap-5.0.1-py3-none-any.whl (24 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting rpds-py>=0.7.1
  Downloading rpds_py-0.17.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 275.8 MB/s eta 0:00:00[2024-02-05 12:29:14.470353] 
Collecting referencing>=0.28.4
  Downloading referencing-0.33.0-py3-none-any.whl (26 kB)
Collecting attrs>=22.2.0
  Downloading attrs-23.2.0-py3-none-any.whl (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.8/60.8 KB 177.8 MB/s eta 0:00:00[2024-02-05 12:29:14.655385] 
Collecting jsonschema-specifications>=2023.03.6
  Downloading jsonschema_specifications-2023.12.1-py3-none-any.whl (18 kB)
Collecting mdurl~=0.1
  Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: pytz, zipp, watchdog, validators, urllib3, tzlocal, tzdata, typing-extensions, tqdm, tornado, toolz, toml, threadpoolctl, tenacity, smmap, six, rpds-py, regex, pygments, protobuf, pillow, packaging, numpy, mdurl, MarkupSafe, joblib, idna, click, charset-normalizer, certifi, cachetools, blinker, attrs, scipy, requests, referencing, python-dateutil, pyarrow, nltk, markdown-it-py, jinja2, importlib-metadata, gitdb, scikit-learn, rich, pydeck, pandas, jsonschema-specifications, gitpython, jsonschema, altair, streamlit
Successfully installed MarkupSafe-2.1.5 altair-5.2.0 attrs-23.2.0 blinker-1.7.0 cachetools-5.3.2 certifi-2024.2.2 charset-normalizer-3.3.2 click-8.1.7 gitdb-4.0.11 gitpython-3.1.41 idna-3.6 importlib-metadata-7.0.1 jinja2-3.1.3 joblib-1.3.2 jsonschema-4.21.1 jsonschema-specifications-2023.12.1 markdown-it-py-3.0.0 mdurl-0.1.2 nltk-3.8.1 numpy-1.26.3 packaging-23.2 pandas-2.2.0 pillow-10.2.0 protobuf-4.25.2 pyarrow-15.0.0 pydeck-0.8.1b0 pygments-2.17.2 python-dateutil-2.8.2 pytz-2024.1 referencing-0.33.0 regex-2023.12.25 requests-2.31.0 rich-13.7.0 rpds-py-0.17.1 scikit-learn-1.4.0 scipy-1.12.0 six-1.16.0 smmap-5.0.1 streamlit-1.31.0 tenacity-8.2.3 threadpoolctl-3.2.0 toml-0.10.2 toolz-0.12.1 tornado-6.4 tqdm-4.66.1 typing-extensions-4.9.0 tzdata-2023.4 tzlocal-5.2 urllib3-2.2.0 validators-0.22.0 watchdog-3.0.0 zipp-3.17.0
WARNING: You are using pip version 22.0.3; however, version 24.0 is available.
You should consider upgrading via the '/home/adminuser/venv/bin/python -m pip install --upgrade pip' command.
Checking if Streamlit is installed
Found Streamlit version 1.31.0 in the environment

────────────────────────────────────────────────────────────────────────────────────────

[12:29:42] 🐍 Python dependencies were installed from /mount/src/spam-gaurd/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[12:29:44] πŸ“¦ Processed dependencies!



[nltk_data] Downloading package punkt to /home/appuser/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt.zip.
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/appuser/nltk_data...
[nltk_data]   Unzipping corpora/stopwords.zip.
/home/adminuser/venv/lib/python3.9/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator TfidfTransformer from version 1.3.2 when using version 1.4.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
  warnings.warn(
/home/adminuser/venv/lib/python3.9/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator TfidfVectorizer from version 1.3.2 when using version 1.4.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
  warnings.warn(
/home/adminuser/venv/lib/python3.9/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator ExtraTreeClassifier from version 1.3.2 when using version 1.4.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
  warnings.warn(
/home/adminuser/venv/lib/python3.9/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator ExtraTreesClassifier from version 1.3.2 when using version 1.4.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
  warnings.warn(
[nltk_data] Downloading package punkt to /home/appuser/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/appuser/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package punkt to /home/appuser/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/appuser/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package punkt to /home/appuser/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/appuser/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package punkt to /home/appuser/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/appuser/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
1 Like

There are warnings about the model having been saved with a different version of scikit-learn and a link pointing to more info on the risks of doing so:

While models saved using one version of scikit-learn might load in other versions, this is entirely unsupported and inadvisable. It should also be kept in mind that operations performed on such data could give different and unexpected results.

1 Like

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