Streamlit App Crashes Unexpectedly After First Successful Run of the Application

I hope you are doing well. I am trying to deploy the following application however it crashes unexpectedly without any meaningful error in the logs.

Goal: The main goal of the application is to allow the user to record an audio for about 3 seconds and then press the classify button to predict the emotion of the audio.

Issue: When the application is deployed in Streamlit Cloud, it successfully predicts the emotion for one audio recording however when the user records a second audio and then clicks on the Classify button the application crashes. Therefore, the application works only for one audio file. I believe it is a RAM resource limit however I am not sure and I would like to get your feedback.

I tried st.cahce, deleting all session states, and st.experimental_rerun however nothing worked. Is there something that is being caching and I miss it?

When I reload/rerun the webpage still does not fixes the issue. Moreover, when the application crashes it is unable to be recovered unless it is rebooted. The only way the application works in Streamlit Cloud is to comment lines 296-298 in the audio_processing.py however this produces incorrect output as the user input data to the model is not normalized. Lastly, I want to mention that the application works perfectly locally without commenting the lines mentioned above and with as many audio recordings as desired.

I do not know why the application can successfully run once and then crash. I believed that if the webpage is reloaded manually, then the application will be completely refreshed and able to run one more success run however this is not the case. If there is a solution that the user needs to hard refresh the application manually each time there is a need to do a new recording will also be accepted.

If you need any more information please let me know. Instructions on how to run the application can be found for all operating systems inside the setup folder in the link below. The main libraries and packages of the application can be found in requirements.txt and packages.txt respectively. Python version used is 3.10.8.

Link to the source code deployed application: GitHub - GeorgiosIoannouCoder/vera-ctp

Thank you very much. I appreciate a lot.

I may be useless here, but my brief, naive thoughts without downloading and running all your code:

Since you’ve identified the crash happens within the audio_processing.py file, have you been able to track down where exactly? You can sprinkle in some os.write statements to pinpoint it since this is just in the cloud.

os.write(1,b'Debug message here\n')

I see there is a cache on your download_model function in your audio_processing.py file. Have you run it without the caching at all to see if it will at least run that way? I know the cache functions can be touchy.

Besides confirming if it runs without any caching, have you tried the experimental cache functions? I’ve found them to be more reliable. Experimental cache primitives - Streamlit Docs

I see you have all the versions set in your requirements file, so I’ll assume you’ve checked your local environment matches the deployment (unless maybe some dependency came in as a different version?).

Thank you very much for your time, effort, and suggestions. By using a profiler, I found out that the application is leaking memory. Therefore, I utilize more session state variables and garbage collector and managed to decrease the memory leak a lot. Now the application is able to do two successful runs before crashing. However, there is still a small data leak as the profiler say inside the function predict() that starts on line 140 within the audio_processing.py file. I cannot see where that data leak is exactly and how to fix it. The main issue I believe inside this function is that it downloads 4 files (71MB, 494MB, 62MB, and 62MB).

Is it possible once I am done with them to delete them and then redownload them when I will need them? It seems that the application maintains a copy of them.

Moreover, is it possible to clear the whole ram memory of the application and restart it at its initial state?

This is the link to the application: https://vera-deployed.streamlit.app/

1 Like

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