App.py
Browse filesimport gradio as gr
from pytube import YouTube
import whisper
from transformers import pipeline
from bark import generate_audio, preload_models
import os
import moviepy.editor as mp
# Load models
asr_model = whisper.load_model("base")
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
# Preload Bark models
preload_models()
def process_video(link):
try:
yt = YouTube(link)
stream = yt.streams.filter(only_audio=True).first()
file_path = stream.download(filename="audio.mp4")
# Step 2: Transcribe English
result = asr_model.transcribe(file_path)
english_text = result["text"]
# Step 3: Translate to Hindi
hindi_text = translator(english_text)[0]['translation_text']
# Step 4: Generate Hindi Audio using Bark
hindi_audio = generate_audio(hindi_text)
with open("hindi.wav", "wb") as f:
f.write(hindi_audio)
# Step 5: Merge audio with video (optional)
original = mp.AudioFileClip("hindi.wav")
video = mp.VideoFileClip(file_path.replace(".mp4", ".mp4")).set_audio(original)
output_path = "dubbed_video.mp4"
video.write_videofile(output_path)
return hindi_text, output_path
except Exception as e:
return str(e), None
gr.Interface(
fn=process_video,
inputs=gr.Textbox(label="Enter YouTube Video URL"),
outputs=[
gr.Textbox(label="Hindi Translation"),
gr.Video(label="Dubbed Hindi Video")
]
).launch()
- requirements.txt +8 -0
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
pytube
|
4 |
+
openai-whisper
|
5 |
+
moviepy
|
6 |
+
gradio
|
7 |
+
ffmpeg-python
|
8 |
+
git+https://github.com/suno-ai/bark.git
|