Spaces:
Sleeping
Sleeping
File size: 1,825 Bytes
d3b9f74 be8b9f6 d3b9f74 be8b9f6 d3b9f74 be8b9f6 6d34151 be8b9f6 25a4665 d3b9f74 51ce539 d3b9f74 be8b9f6 e2f3c1e be8b9f6 e2f3c1e be8b9f6 e2f3c1e be8b9f6 e2f3c1e d3b9f74 be8b9f6 d3b9f74 e2f3c1e 25a4665 e2f3c1e be8b9f6 e2f3c1e be8b9f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import boto3
import gradio as gr
from transformers import pipeline
import tempfile
import os
# from huggingface_hub import login
#
# with open("../token.txt", "r") as file:
# token = file.readline().strip()
#
#
# login(token=token, add_to_git_credential=True)
pipe = pipeline(model="dacavi/whisper-small-es")
def translate_text(text, target_language_code):
translate = boto3.client('translate', region_name='us-east-1')
response = translate.translate_text(
Text=text,
SourceLanguageCode='es', # Auto-detect source language
TargetLanguageCode=target_language_code
)
translated_text = response['TranslatedText']
return translated_text
def translate_video(video_url,language):
if video_url and language:
# Download video and extract audio
with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio:
# os.system(f"yt-dlp -o {temp_audio.name} -x --audio-format wav {video_url}")
os.system(f"yt-dlp -o audioSample.wav -x --audio-format wav {video_url}")
print("Downloaded audio:", temp_audio.name)
# Transcribe audio
text = pipe("audioSample.wav")["text"]
translatedText = translate_text(text,language)
# Clean up temporary files
os.remove("audioSample.wav")
else:
translatedText = "Please fill in both parameters."
return translatedText
iface = gr.Interface(
fn=translate_video,
inputs=[gr.Textbox(label="Video URL"),
gr.Dropdown(choices=["en", "fr", "de", "it"], label="Select Target Language")
],
outputs="text",
live=True,
title="SPANISH VIDEO TRANSLATION",
description="Paste the URL of a Spanish video to translate the text to any of the available languages.",
)
iface.launch()
|