App gets collapsed in cloud

Hi folks. I have a deployed an streamlit application for age-gender-race-emotion detection using deepface library. In the app, I have provided a select box with four different of actions like above mentioned. If we are experimenting the application, its working for only those selections of the select box. If we are experimenting the application on third time, the app is getting collapsed. I have checked all the logs. But in the logs there is no reason for why the app is getting collapsed. I am attaching my logs file and website demo link. Requesting anyone to get out of this error. It’s my academic project for the semester.

The following is my code:

import numpy as np
import pandas as pd
from deepface import DeepFace
import streamlit as st
import cv2
import base64
import time

st.set_page_config(layout="wide")

def get_video_base64(video_path):
    with open(video_path, "rb") as file:
        video_bytes = file.read()
        base64_encoded = base64.b64encode(video_bytes).decode("utf-8")
        return base64_encoded

video_path = "deep.mp4"
video_base64 = get_video_base64(video_path)

video_html = f"""
	<style>
	#myVideo {{
		position: fixed;
		right: 0;
		bottom: 0;
		min-width: 100%; 
		min-height: 100%;
	}}
	.content {{
		position: fixed;
		bottom: 0;
		background: rgba(0, 0, 0, 0.5);
		color: #f1f1f1;
		width: 100%;
		padding: 20px;
	}}

	</style>

	<video autoplay loop muted id="myVideo">
		<source type="video/mp4" src="data:video/mp4;base64,{video_base64}">
	</video>
"""

st.markdown(video_html, unsafe_allow_html=True)



cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

import tempfile
import os

def upload():
    image=None
    initial_image = st.camera_input('Take a picture')
    original_image = initial_image
    temp_path = None
    if initial_image is not None:
        bytes_data = initial_image.getvalue()
        image = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)

    return image, original_image


def main():
    
    actions = ['age', 'gender', 'race', 'emotion']
    option2 = st.selectbox('Choose the following actions:', actions)
    
    
    
   
    if st.checkbox('Take a picture for prediction'):
        
        image, original_image= upload()
        if original_image is not None and original_image is not None and st.button('Prediction'):  # Check if original_image is not None
            st.warning('Wait for few seconds!!')
            progress_bar = st.progress(0.0)
            status_text = st.empty()
            
            result = DeepFace.analyze(image, actions=option2)
            
            for i in range(100):
                progress_bar.progress((i + 1) / 100)
                status_text.text(f"Processing {i+1}%")
                time.sleep(0.01)
            
            progress_bar.empty()
            gray_frame = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            faces = cascade.detectMultiScale(gray_frame, 1.1, 3)
            faces = sorted(faces, key=lambda f: -f[2] * f[3])

            if len(faces) > 0:
                x,y,w,h=faces[0]
                
                cv2.rectangle(image, (x, y), (x+w, y+h), (4, 29, 255), 2, cv2.LINE_4)
                user_selected_items = list(result[0].keys())
                if 'age' in user_selected_items:
                    age_label='Age: '+str(result[0]['age'])
                    cv2.putText(image, age_label, (x+w+10, y+45), cv2.FONT_ITALIC,0.5 ,(252,0,8), 2)
                if 'dominant_gender' in user_selected_items:
                    gender_label='Gender: '+str(result[0]['dominant_gender'])
                    cv2.putText(image, gender_label, (x+w+10, y+75), cv2.FONT_ITALIC,0.5, (1,122,17), 2)
                if 'dominant_race' in user_selected_items:
                    race_label='Race: '+str(result[0]['dominant_race']).title()
                    cv2.putText(image, race_label, (x+w+10, y+105), cv2.FONT_ITALIC,0.5, (148,0,211), 2)
                if 'dominant_emotion' in user_selected_items:
                    emotion_label='Emotion: '+str(result[0]['dominant_emotion']).title()
                    cv2.putText(image, emotion_label, (x+w+10, y+135), cv2.FONT_ITALIC, 0.5,(4,4,4), 2)

            st.image(image, channels='BGR')
   
if __name__ == '__main__':
    main()

The following is my demo link:
https://age-gender-race-emotion-recognition-website.streamlit.app/

Hi @Guna_Sekhar_Venkata,

It looks like your app has exceeded Community Cloud’s resource limit (which might have played a role in the behavior you were seeing, although I’m not positive) – if the app is for an educational or nonprofit use case, you can reach out to the Streamlit Community Cloud support team by following the steps outlined here and they can increase the resource limit for this app. Otherwise, I’d recommend seeing if you can decrease the resource usage of your app (check out our docs on caching) or explore other platforms for deploying your app.

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