Swar / app.py
Bagda's picture
Update app.py
708d755 verified
raw
history blame
2.28 kB
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
from moviepy.editor import VideoFileClip
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa
# Step 1: Download YouTube video as audio
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")
# Step 2: Extract audio as WAV
video = VideoFileClip("video_audio.mp4")
audio = video.audio
audio.write_audiofile("output_audio.wav")
# Step 3: Speech-to-text with Whisper-Small
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)