Update app.py
Browse files
app.py
CHANGED
|
@@ -234,4 +234,41 @@ if __name__ == "__main__":
|
|
| 234 |
if "gradio" in sys.argv:
|
| 235 |
run_gradio_ui()
|
| 236 |
else:
|
| 237 |
-
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
if "gradio" in sys.argv:
|
| 235 |
run_gradio_ui()
|
| 236 |
else:
|
| 237 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
| 238 |
+
import whisper
|
| 239 |
+
from transformers import pipeline
|
| 240 |
+
from gtts import gTTS
|
| 241 |
+
import gradio as gr
|
| 242 |
+
import os
|
| 243 |
+
|
| 244 |
+
# Load Whisper model
|
| 245 |
+
whisper_model = whisper.load_model("small")
|
| 246 |
+
|
| 247 |
+
# Load translation pipeline (English to Hindi)
|
| 248 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
|
| 249 |
+
|
| 250 |
+
def transcribe_translate_dub(audio_path):
|
| 251 |
+
# Step 1: Transcribe audio using Whisper
|
| 252 |
+
result = whisper_model.transcribe(audio_path)
|
| 253 |
+
english_text = result["text"]
|
| 254 |
+
|
| 255 |
+
# Step 2: Translate English to Hindi
|
| 256 |
+
translated = translator(english_text)[0]["translation_text"]
|
| 257 |
+
|
| 258 |
+
# Step 3: Text-to-Speech (Hindi)
|
| 259 |
+
tts = gTTS(translated, lang='hi')
|
| 260 |
+
tts.save("dubbed_audio.mp3")
|
| 261 |
+
|
| 262 |
+
return translated, "dubbed_audio.mp3"
|
| 263 |
+
|
| 264 |
+
# Gradio UI
|
| 265 |
+
gr.Interface(
|
| 266 |
+
fn=transcribe_translate_dub,
|
| 267 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Upload English Audio"),
|
| 268 |
+
outputs=[
|
| 269 |
+
gr.Textbox(label="Hindi Translation"),
|
| 270 |
+
gr.Audio(label="Hindi Dubbed Audio")
|
| 271 |
+
],
|
| 272 |
+
title="🎙️ English to Hindi Video Dubbing AI",
|
| 273 |
+
description="Upload English audio, get Hindi translation and dubbed voice."
|
| 274 |
+
).launch()
|