File size: 2,210 Bytes
891d755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf5a004
6480da6
8162cb8
 
 
 
6480da6
 
 
 
8162cb8
6480da6
 
 
8162cb8
 
bf5a004
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8162cb8
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

import gradio as gr

def dub_video(video_url):
    # यहाँ आप बैकएंड फंक्शन को कॉल करें, जो वीडियो डाउनलोड करे, ऑडियो निकाले, हिंदी में डब करे और डब्ड वीडियो रिटर्न करे
    # उदाहरण के लिए: processed_video_path = backend_dubbing_function(video_url, "hindi")
    # return processed_video_path
    return "Processed video path will be returned here (replace with actual function call)"

demo = gr.Interface(
    fn=dub_video,
    inputs=gr.Textbox(label="Enter video URL"),
    outputs=gr.Video(label="Hindi Dubbed Video"),
    title="Video Dubbing AI (Hindi)",
    description="Enter a video URL to get it dubbed in Hindi."
)

demo.launch()


from pytube import YouTube

video_url = "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"
yt = YouTube(video_url)
stream = yt.streams.filter(only_audio=True).first()
stream.download(filename="video_audio.mp4")

from moviepy.editor import VideoFileClip

video = VideoFileClip("video_audio.mp4")
audio = video.audio
audio.write_audiofile("output_audio.wav")



from transformers import WhisperProcessor, WhisperForConditionalGeneration
import torch
from datasets import load_dataset

# Load model and processor
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")

# Optional: Use GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device)

# Load sample audio (here using a dummy dataset, aap apni audio file bhi use kar sakte hain)
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = ds[0]["audio"]

# Prepare audio input
input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
input_features = input_features.to(device)

# Generate transcription
predicted_ids = model.generate(input_features)

# Decode transcription
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
print(transcription)