import streamlit as st import cv2 import numpy as np from camera_input_live import camera_input_live # Set page config st.set_page_config(page_title="Real-Time Video AI Demo", layout="wide") # Title and description st.title("Real-Time Video AI Processing with Streamlit") st.write("This app demonstrates real-time webcam video processing with AI filters using Streamlit and OpenCV.") # Sidebar for filter selection st.sidebar.header("Filter Controls") filter_type = st.sidebar.selectbox( "Choose a filter", ["None", "Grayscale", "Canny Edge Detection", "Blur"] ) # Initialize the camera input image = camera_input_live() # Process and display the video feed if image is not None: # Convert the image from bytes to numpy array nparr = np.frombuffer(image.getvalue(), np.uint8) frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR) # Apply selected filter if filter_type == "Grayscale": frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Convert back to 3 channels for Streamlit display frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) elif filter_type == "Canny Edge Detection": frame = cv2.Canny(frame, 100, 200) # Convert back to 3 channels for Streamlit display frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) elif filter_type == "Blur": frame = cv2.GaussianBlur(frame, (15, 15), 0) # Display the processed frame st.image(frame, channels="RGB", caption="Live Video Feed") else: st.warning("Waiting for camera input...") # Instructions st.sidebar.markdown(""" ### Instructions 1. Allow camera access when prompted 2. Select a filter from the dropdown 3. View the processed video in real-time 4. Try different filters to see AI processing in action """) # Requirements note st.sidebar.info("Make sure you have installed: streamlit, opencv-python, numpy, streamlit-camera-input-live")