Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| import easyocr | |
| import tempfile | |
| # AI model load ho raha hai | |
| reader = easyocr.Reader(['en'], gpu=False) | |
| def remove_text_from_video(video_path): | |
| if video_path is None: | |
| return None | |
| cap = cv2.VideoCapture(video_path) | |
| fps = int(cap.get(cv2.CAP_PROP_FPS)) | |
| width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
| height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| # Processed video save karne ke liye temporary file | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') | |
| output_path = temp_file.name | |
| fourcc = cv2.VideoWriter_fourcc(*'mp4v') | |
| out = cv2.VideoWriter(output_path, fourcc, fps, (width, height)) | |
| # Hugging Face free tier ko crash hone se bachane ke liye 150 frames (approx 5 sec) ki limit | |
| max_frames = 150 | |
| frame_count = 0 | |
| while cap.isOpened(): | |
| ret, frame = cap.read() | |
| if not ret or frame_count >= max_frames: | |
| break | |
| # Text dhundhna aur mask banana | |
| results = reader.readtext(frame) | |
| mask = np.zeros(frame.shape[:2], dtype=np.uint8) | |
| for (bbox, text, prob) in results: | |
| (tl, tr, br, bl) = bbox | |
| cv2.rectangle(mask, (int(tl[0]), int(tl[1])), (int(br[0]), int(br[1])), 255, -1) | |
| # Mask ko thoda bada karna taaki text puri tarah cover ho | |
| kernel = np.ones((5,5), np.uint8) | |
| mask = cv2.dilate(mask, kernel, iterations=1) | |
| # Frame se text hata kar background fill karna (Inpainting) | |
| result_frame = cv2.inpaint(frame, mask, 3, cv2.INPAINT_TELEA) | |
| out.write(result_frame) | |
| frame_count += 1 | |
| cap.release() | |
| out.release() | |
| return output_path | |
| # Gradio Video UI | |
| interface = gr.Interface( | |
| fn=remove_text_from_video, | |
| inputs=gr.Video(label="Upload Video (Test karne ke liye 2-5 sec ki clip daalein)"), | |
| outputs=gr.Video(label="Result Video"), | |
| title="Hyco Video Text Remover", | |
| description="Isme apni clip upload karein. AI har frame se captions dhundhega aur unhe automatically hata dega." | |
| ) | |
| interface.launch() | |