File size: 2,171 Bytes
fc2c793
 
 
 
61fb20e
fc2c793
61fb20e
fc2c793
 
61fb20e
 
 
 
 
 
 
 
fc2c793
61fb20e
 
 
fc2c793
61fb20e
 
fc2c793
61fb20e
 
 
fc2c793
61fb20e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc2c793
61fb20e
fc2c793
61fb20e
fc2c793
61fb20e
 
 
 
 
fc2c793
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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()