import cv2 import gradio as gr import os def convert_to_grayscale(video_file): cap = cv2.VideoCapture(video_file) output_file = "output.mp4" width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = int(cap.get(cv2.CAP_PROP_FPS)) fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(output_file, fourcc, fps, (width, height), isColor=False) while(cap.isOpened()): ret, frame = cap.read() if not ret: break gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) out.write(gray) cap.release() out.release() return output_file demo = gr.Interface( fn=convert_to_grayscale, title="Video Upload and Display", inputs=gr.Video(label="Upload Video", height=500, width=500), outputs=gr.Video(label="Grayscale Video", height=500, width=500), ) demo.launch()