Streamlit Not Working for Librosa

I have built a model to take an audio file and classify its emotion. The model works perfectly in Google Colab and now I am working to make it available through Streamlit. Following are the libraries I use and I have verified the versions in my program. I have added these on the requirements.txt file.

scikit-learn==1.2.2
numpy==1.21.0
pandas==1.5.3
joblib==1.3.2
librosa==0.10.0.post2
xgboost==1.7.6

Based on the previous discussion on this page, I have also added another file packages.txt with the following code: libsndfile1-dev

Below is the error I am getting. Please help with this.

Hi @Chirag_Saraogi, and welcome to our community! :wave:

You may need to install the libsndfile1 package (not Dev) in your packages.txt file.

If that doesn’t fix the issue, could you please provide us with the full error log trace?

Thanks,
Charly

Hi @Charly_Wargnier ,

thank you so much for helping me with this. I did change the code in the packages.txt file but it still gave the same error. Below is the error log. Please let me know if I can provide any more information about the project to help resolve this. Thank you.

Can you provide the log trace in a text format please?

Thanks,
Charly

Hi @Charly_Wargnier

Below is the log in text format.

Collecting streamlit
  Downloading streamlit-1.25.0-py2.py3-none-any.whl (8.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.1/8.1 MB 16.1 MB/s eta 0:00:00[2023-08-21 13:23:42.911385] 
Collecting pillow<10,>=7.1.0
  Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 19.1 MB/s eta 0:00:00
Collecting pympler<2,>=0.9
  Downloading Pympler-1.0.1-py3-none-any.whl (164 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 164.8/164.8 KB 17.6 MB/s eta 0:00:00[2023-08-21 13:23:45.746907] 
Collecting typing-extensions<5,>=4.1.0
  Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting packaging<24,>=16.8
  Downloading packaging-23.1-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 KB 110.6 MB/s eta 0:00:00
Collecting pyarrow>=6.0
  Downloading pyarrow-12.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 39.0/39.0 MB 46.6 MB/s eta 0:00:00[2023-08-21 13:23:48.506478] 
Collecting blinker<2,>=1.0.0
  Downloading blinker-1.6.2-py3-none-any.whl (13 kB)
Collecting tenacity<9,>=8.1.0
  Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)
Collecting tzlocal<5,>=1.1
  Downloading tzlocal-4.3.1-py3-none-any.whl (20 kB)
Collecting pandas<3,>=1.3.0
  Downloading pandas-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.4/12.4 MB 13.6 MB/s eta 0:00:00[2023-08-21 13:23:52.163204] 
Collecting cachetools<6,>=4.0
  Downloading cachetools-5.3.1-py3-none-any.whl (9.3 kB)
Collecting protobuf<5,>=3.20
  Downloading protobuf-4.24.1-cp37-abi3-manylinux2014_x86_64.whl (311 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 311.4/311.4 KB 141.3 MB/s eta 0:00:00[2023-08-21 13:23:54.755225] 
Collecting tornado<7,>=6.0.3
  Downloading tornado-6.3.3-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 427.7/427.7 KB 44.9 MB/s eta 0:00:00
Collecting toml<2,>=0.10.1
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
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 141.9 MB/s eta 0:00:00[2023-08-21 13:23:55.835518] 
Collecting watchdog>=2.1.5
  Downloading watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.1/82.1 KB 80.2 MB/s eta 0:00:00
Collecting importlib-metadata<7,>=1.4
  Downloading importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting gitpython!=3.1.19,<4,>=3.0.7
  Downloading GitPython-3.1.32-py3-none-any.whl (188 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 188.5/188.5 KB 128.9 MB/s eta 0:00:00
Collecting rich<14,>=10.14.0
  Downloading rich-13.5.2-py3-none-any.whl (239 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 239.7/239.7 KB 154.7 MB/s eta 0:00:00[2023-08-21 13:23:58.115319] 
Collecting click<9,>=7.0
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 KB 137.9 MB/s eta 0:00:00[2023-08-21 13:23:58.293502] 
Collecting altair<6,>=4.0
  Downloading altair-5.0.1-py3-none-any.whl (471 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 471.5/471.5 KB 8.4 MB/s eta 0:00:00
Collecting requests<3,>=2.18
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 135.8 MB/s eta 0:00:00[2023-08-21 13:23:59.002573] 
Collecting pydeck<1,>=0.8
  Downloading pydeck-0.8.0-py2.py3-none-any.whl (4.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 12.9 MB/s eta 0:00:00
Collecting validators<1,>=0.2
  Downloading validators-0.21.2-py3-none-any.whl (25 kB)
Collecting numpy<2,>=1.19.3
  Downloading numpy-1.25.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.3/18.3 MB 41.6 MB/s eta 0:00:00[2023-08-21 13:24:02.671825] 
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 KB 137.4 MB/s eta 0:00:00
Collecting toolz
  Downloading toolz-0.12.0-py3-none-any.whl (55 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 KB 114.9 MB/s eta 0:00:00[2023-08-21 13:24:03.735575] 
Collecting jsonschema>=3.0
  Downloading jsonschema-4.19.0-py3-none-any.whl (83 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 83.4/83.4 KB 170.5 MB/s eta 0:00:00[2023-08-21 13:24:04.111393] 
Collecting gitdb<5,>=4.0.1
  Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 KB 98.3 MB/s eta 0:00:00[2023-08-21 13:24:04.266424] 
Collecting zipp>=0.5
  Downloading zipp-3.16.2-py3-none-any.whl (7.2 kB)
Collecting pytz>=2020.1
  Downloading pytz-2023.3-py2.py3-none-any.whl (502 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.3/502.3 KB 140.4 MB/s eta 0:00:00[2023-08-21 13:24:05.716901] 
Collecting tzdata>=2022.1
  Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 KB 143.7 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 KB 130.8 MB/s eta 0:00:00[2023-08-21 13:24:06.534639] 
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.0.4-py3-none-any.whl (123 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 123.9/123.9 KB 130.0 MB/s eta 0:00:00[2023-08-21 13:24:06.922412] 
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 202.1/202.1 KB 160.1 MB/s eta 0:00:00[2023-08-21 13:24:07.771267] 
Collecting certifi>=2017.4.17
  Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.3/158.3 KB 110.3 MB/s eta 0:00:00[2023-08-21 13:24:07.932946] 
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 125.6 MB/s eta 0:00:00[2023-08-21 13:24:08.231447] 
Collecting pygments<3.0.0,>=2.13.0
  Downloading Pygments-2.16.1-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 12.2 MB/s eta 0:00:00
Collecting pytz-deprecation-shim
  Downloading pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl (15 kB)
Collecting smmap<6,>=3.0.1
  Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting rpds-py>=0.7.1
  Downloading rpds_py-0.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 39.3 MB/s eta 0:00:00
Collecting attrs>=22.2.0
  Downloading attrs-23.1.0-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 KB 118.2 MB/s eta 0:00:00[2023-08-21 13:24:11.653700] 
Collecting referencing>=0.28.4
  Downloading referencing-0.30.2-py3-none-any.whl (25 kB)
Collecting jsonschema-specifications>=2023.03.6
  Downloading jsonschema_specifications-2023.7.1-py3-none-any.whl (17 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, tzdata, typing-extensions, tornado, toolz, toml, tenacity, smmap, six, rpds-py, pympler, pygments, protobuf, pillow, packaging, numpy, mdurl, MarkupSafe, idna, click, charset-normalizer, certifi, cachetools, blinker, attrs, requests, referencing, pytz-deprecation-shim, python-dateutil, pyarrow, markdown-it-py, jinja2, importlib-metadata, gitdb, tzlocal, rich, pydeck, pandas, jsonschema-specifications, gitpython, jsonschema, altair, streamlit
  Attempting uninstall: pytz
    Found existing installation: pytz 2023.3
    Uninstalling pytz-2023.3:
      Successfully uninstalled pytz-2023.3
  Attempting uninstall: urllib3
    Found existing installation: urllib3 2.0.4
    Uninstalling urllib3-2.0.4:
      Successfully uninstalled urllib3-2.0.4
  Attempting uninstall: typing-extensions
    Found existing installation: typing_extensions 4.7.1
    Uninstalling typing_extensions-4.7.1:
      Successfully uninstalled typing_extensions-4.7.1
  Attempting uninstall: six
    Found existing installation: six 1.16.0
    Uninstalling six-1.16.0:
      Successfully uninstalled six-1.16.0
  Attempting uninstall: packaging
    Found existing installation: packaging 23.1
    Uninstalling packaging-23.1:
      Successfully uninstalled packaging-23.1
  Attempting uninstall: numpy
    Found existing installation: numpy 1.23.5
    Uninstalling numpy-1.23.5:
      Successfully uninstalled numpy-1.23.5
  Attempting uninstall: idna
    Found existing installation: idna 3.4
    Uninstalling idna-3.4:
      Successfully uninstalled idna-3.4
  Attempting uninstall: charset-normalizer
    Found existing installation: charset-normalizer 3.2.0
    Uninstalling charset-normalizer-3.2.0:
      Successfully uninstalled charset-normalizer-3.2.0
  Attempting uninstall: certifi
    Found existing installation: certifi 2023.7.22
    Uninstalling certifi-2023.7.22:
      Successfully uninstalled certifi-2023.7.22
  Attempting uninstall: requests
    Found existing installation: requests 2.31.0
    Uninstalling requests-2.31.0:
      Successfully uninstalled requests-2.31.0
  Attempting uninstall: python-dateutil
    Found existing installation: python-dateutil 2.8.2
    Uninstalling python-dateutil-2.8.2:
      Successfully uninstalled python-dateutil-2.8.2
  Attempting uninstall: pandas
    Found existing installation: pandas 1.5.3
    Uninstalling pandas-1.5.3:
      Successfully uninstalled pandas-1.5.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
numba 0.57.1 requires numpy<1.25,>=1.21, but you have numpy 1.25.2 which is incompatible.
Successfully installed MarkupSafe-2.1.3 altair-5.0.1 attrs-23.1.0 blinker-1.6.2 cachetools-5.3.1 certifi-2023.7.22 charset-normalizer-3.2.0 click-8.1.7 gitdb-4.0.10 gitpython-3.1.32 idna-3.4 importlib-metadata-6.8.0 jinja2-3.1.2 jsonschema-4.19.0 jsonschema-specifications-2023.7.1 markdown-it-py-3.0.0 mdurl-0.1.2 numpy-1.25.2 packaging-23.1 pandas-2.0.3 pillow-9.5.0 protobuf-4.24.1 pyarrow-12.0.1 pydeck-0.8.0 pygments-2.16.1 pympler-1.0.1 python-dateutil-2.8.2 pytz-2023.3 pytz-deprecation-shim-0.1.0.post0 referencing-0.30.2 requests-2.31.0 rich-13.5.2 rpds-py-0.9.2 six-1.16.0 smmap-5.0.0 streamlit-1.25.0 tenacity-8.2.3 toml-0.10.2 toolz-0.12.0 tornado-6.3.3 typing-extensions-4.7.1 tzdata-2023.3 tzlocal-4.3.1 urllib3-2.0.4 validators-0.21.2 watchdog-3.0.0 zipp-3.16.2
WARNING: You are using pip version 22.0.3; however, version 23.2.1 is available.
You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.

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

[13:25:41] πŸ“¦ Processed dependencies!

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.




2023-08-21 13:26:30.950 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/app/audio_emotion_detection/Emotion_Prediction.py", line 44, in <module>
    main()
  File "/app/audio_emotion_detection/Emotion_Prediction.py", line 27, in main
    extracted_features = extract_audio_features(audio_data)
  File "/app/audio_emotion_detection/audio_feature_extractor.py", line 73, in extract_audio_features
    y, sr = librosa.load(audio_path, sr = None)
  File "/home/appuser/venv/lib/python3.9/site-packages/lazy_loader/__init__.py", line 78, in __getattr__
    attr = getattr(submod, name)
  File "/home/appuser/venv/lib/python3.9/site-packages/lazy_loader/__init__.py", line 77, in __getattr__
    submod = importlib.import_module(submod_path)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/appuser/venv/lib/python3.9/site-packages/librosa/core/audio.py", line 17, in <module>
    from numba import jit, stencil, guvectorize
  File "/home/appuser/venv/lib/python3.9/site-packages/numba/__init__.py", line 55, in <module>
    _ensure_critical_deps()
  File "/home/appuser/venv/lib/python3.9/site-packages/numba/__init__.py", line 42, in _ensure_critical_deps
    raise ImportError("Numba needs NumPy 1.24 or less")
ImportError: Numba needs NumPy 1.24 or less
2023-08-21 14:02:14.465 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/app/audio_emotion_detection/Emotion_Prediction.py", line 44, in <module>
    main()
  File "/app/audio_emotion_detection/Emotion_Prediction.py", line 27, in main
    extracted_features = extract_audio_features(audio_data)
  File "/app/audio_emotion_detection/audio_feature_extractor.py", line 73, in extract_audio_features
    y, sr = librosa.load(audio_path, sr = None)
  File "/home/appuser/venv/lib/python3.9/site-packages/lazy_loader/__init__.py", line 78, in __getattr__
    attr = getattr(submod, name)
  File "/home/appuser/venv/lib/python3.9/site-packages/lazy_loader/__init__.py", line 77, in __getattr__
    submod = importlib.import_module(submod_path)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/appuser/venv/lib/python3.9/site-packages/librosa/core/audio.py", line 17, in <module>
    from numba import jit, stencil, guvectorize
  File "/home/appuser/venv/lib/python3.9/site-packages/numba/__init__.py", line 55, in <module>
    _ensure_critical_deps()
  File "/home/appuser/venv/lib/python3.9/site-packages/numba/__init__.py", line 42, in _ensure_critical_deps
    raise ImportError("Numba needs NumPy 1.24 or less")
ImportError: Numba needs NumPy 1.24 or less

Thanks, @Chirag_Saraogi!

The error message indicates that Numba needs NumPy 1.24 or a lesser version

Can you try downgrading, e.g.:

pip install numpy==1.24

Thanks.
Charly

@Charly_Wargnier

I am using the following code in the requirements file.

numpy==1.21.0

Should I install NumPy in the packages.txt code? I tried different versions and many ways to resolve the issue but could not find any way to resolve it. Please help with this.

Thank you

@Charly_Wargnier

I am sorry, I am using the versions below

scikit-learn==1.2.2
numpy==1.23.5
pandas==1.5.3
joblib==1.3.2
librosa==0.10.0.post2
xgboost==1.7.6

Add streamlit to your requirements.txt.

Hi Goyo,

Thank you for your reply. I have added these libraries and their versions to the requirements.txt file already. But I am still not able to resolve the error.

Thank you

Please share the link to your public github repo.

1 Like

Hi @Franky1 ,

Thank you for helping me with this. Below is the link to my GitHub Repository for the project.

Thank you.

Hi @Charly_Wargnier

I have already downgraded the NumPy version. Please help me resolve this. Below is the link to my github repository.

Thank you

Hi @Franky1

Please help me resolve the issue with the Streamlit. I really want to continue using Streamlit for my projects.

Thank you

I cannot find streamlit in your requirements.txt.

Hi @Goyo

Based on what I understood, Streamlit was already installed and I am not able to resolve the issue by adding streamlit.

Thank you

If you don’t add streamlit to your requirements file, it is automatically installed at the end. This sometimes can trigger the installation of different versions of the same packages you are requesting. So you can end up with numpy==1.25.2 even if you requested a lower version. You can see it happening in the logs.

I fixed some bugs, see my fork and pull request:

App seems to work, however, there are still some warnings in the console…

1 Like

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