Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
# - Lyrics mode: Enable word_timestamps for music-like precision.
|
| 9 |
# - Trim: Skip short/silent segments (<0.5s).
|
| 10 |
# 4. Enhancements: Word emphasis (e.g., wrap "wow" in bold/color tags).
|
| 11 |
-
# 5. Translation: Optional to 120+ langs via
|
| 12 |
# 6. ASS subtitle creation: Styled with fonts/colors/sizes/positions/animations/emojis.
|
| 13 |
# 7. Burn to video: FFmpeg overlays HD output, no watermark.
|
| 14 |
# 8. UI: Simple, free, viral-ready for Reels/YouTube.
|
|
@@ -21,7 +21,7 @@ from transformers import pipeline
|
|
| 21 |
import torch
|
| 22 |
import ffmpeg
|
| 23 |
from yt_dlp import YoutubeDL
|
| 24 |
-
from
|
| 25 |
|
| 26 |
# Model options (lighter for speed)
|
| 27 |
MODEL_CHOICES = {
|
|
@@ -36,9 +36,7 @@ FONTS = ["Arial", "Montserrat"] # Add more if custom fonts available
|
|
| 36 |
COLORS = ["white", "yellow", "black"]
|
| 37 |
SIZES = ["small (24)", "medium (32)", "large (40)"]
|
| 38 |
POSITIONS = ["bottom", "top"]
|
| 39 |
-
LANGUAGES = ["en", "hi", "fr", "es"] # Sample; extend to 120+ with
|
| 40 |
-
|
| 41 |
-
translator = Translator() # googletrans instance
|
| 42 |
|
| 43 |
def download_youtube(url, progress=gr.Progress()):
|
| 44 |
"""Download YouTube video using yt-dlp (Blink-like: social input support)."""
|
|
@@ -106,11 +104,13 @@ def transcribe_audio(audio_path, model_name, lyrics_mode, progress=gr.Progress()
|
|
| 106 |
return trimmed_segments # List of {'text': , 'start': , 'end': }
|
| 107 |
|
| 108 |
def translate_text(text, target_lang):
|
| 109 |
-
"""Optional translation (Blink-like: 120+ langs)."""
|
| 110 |
if target_lang == "en": # No translate
|
| 111 |
return text
|
| 112 |
try:
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
except Exception:
|
| 115 |
return text # Fallback on error
|
| 116 |
|
|
|
|
| 8 |
# - Lyrics mode: Enable word_timestamps for music-like precision.
|
| 9 |
# - Trim: Skip short/silent segments (<0.5s).
|
| 10 |
# 4. Enhancements: Word emphasis (e.g., wrap "wow" in bold/color tags).
|
| 11 |
+
# 5. Translation: Optional to 120+ langs via deep-translator (stable, fixes googletrans errors).
|
| 12 |
# 6. ASS subtitle creation: Styled with fonts/colors/sizes/positions/animations/emojis.
|
| 13 |
# 7. Burn to video: FFmpeg overlays HD output, no watermark.
|
| 14 |
# 8. UI: Simple, free, viral-ready for Reels/YouTube.
|
|
|
|
| 21 |
import torch
|
| 22 |
import ffmpeg
|
| 23 |
from yt_dlp import YoutubeDL
|
| 24 |
+
from deep_translator import GoogleTranslator # Stable replacement for googletrans
|
| 25 |
|
| 26 |
# Model options (lighter for speed)
|
| 27 |
MODEL_CHOICES = {
|
|
|
|
| 36 |
COLORS = ["white", "yellow", "black"]
|
| 37 |
SIZES = ["small (24)", "medium (32)", "large (40)"]
|
| 38 |
POSITIONS = ["bottom", "top"]
|
| 39 |
+
LANGUAGES = ["en", "hi", "fr", "es"] # Sample; extend to 120+ with deep-translator
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def download_youtube(url, progress=gr.Progress()):
|
| 42 |
"""Download YouTube video using yt-dlp (Blink-like: social input support)."""
|
|
|
|
| 104 |
return trimmed_segments # List of {'text': , 'start': , 'end': }
|
| 105 |
|
| 106 |
def translate_text(text, target_lang):
|
| 107 |
+
"""Optional translation (Blink-like: 120+ langs, using deep-translator)."""
|
| 108 |
if target_lang == "en": # No translate
|
| 109 |
return text
|
| 110 |
try:
|
| 111 |
+
# Instantiate per call for stability (source auto-detect)
|
| 112 |
+
translator = GoogleTranslator(source='auto', target=target_lang)
|
| 113 |
+
return translator.translate(text)
|
| 114 |
except Exception:
|
| 115 |
return text # Fallback on error
|
| 116 |
|