|
|
|
import gradio as gr |
|
|
|
def dub_video(video_url): |
|
|
|
|
|
|
|
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 |
|
from moviepy.editor import VideoFileClip |
|
from transformers import WhisperProcessor, WhisperForConditionalGeneration |
|
import librosa |
|
|
|
|
|
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") |
|
|
|
|
|
video = VideoFileClip("video_audio.mp4") |
|
audio = video.audio |
|
audio.write_audiofile("output_audio.wav") |
|
|
|
|
|
processor = WhisperProcessor.from_pretrained("openai/whisper-small") |
|
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small") |
|
audio, sr = librosa.load("output_audio.wav", sr=16000) |
|
input_features = processor(audio, sampling_rate=sr, return_tensors="pt").input_features |
|
predicted_ids = model.generate(input_features) |
|
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0] |
|
print(transcription) |
|
|
|
def translate_long_text(text): |
|
chunks = [text[i:i+400] for i in range(0, len(text), 400)] |
|
translated_chunks = [] |
|
|
|
for chunk in chunks: |
|
translated = translator(chunk, max_length=512)[0]['translation_text'] |
|
translated_chunks.append(translated) |
|
|
|
return " ".join(translated_chunks) |
|
|
|
long_english_text = "Your long English text here..." |
|
hindi_translation = translate_long_text(long_english_text) |
|
|
|
|