Salman11223's picture
Update app.py
58110bd verified
raw
history blame
2.83 kB
from translate import Translate # Import the Translate class
import gradio as gr
import os
def app(video_path, original_language, target_language):
translator = Translate(video_path, original_language, target_language)
translated_text_file = translator.transcribe_and_translate()
# Save the file with the desired name, ensuring a unique name if needed
saved_file_path = "translated_text.txt" # Replace with your preferred filename
if os.path.exists(saved_file_path):
base, ext = os.path.splitext(saved_file_path)
counter = 1
while os.path.exists(f"{base}_{counter}{ext}"):
counter += 1
saved_file_path = f"{base}_{counter}{ext}"
os.rename(translated_text_file, saved_file_path)
return saved_file_path
# Gradio's built-in File component handles download functionality
interface_text_file = gr.Interface(
fn=app,
inputs=[
gr.File(label="Upload Text File"),
gr.Dropdown(["English", "German", "French", "Spanish"], label="Original Language"),
gr.Dropdown(["English", "German", "French", "Spanish", "Urdu"], label="Targeted Language"),
],
outputs=gr.File(label="Translated Text File"), # Gradio provides the download link
)
interface_text_file.launch(debug=True)
# import gradio as gr
# import os
# import moviepy.editor as mp
# import assemblyai as aai
# import requests
# import azure.cognitiveservices.speech as speechsdk
# from moviepy.editor import AudioFileClip
# from gradio_client import Client
# def app(video_path,original_language, target_language):
# translator = Translate(video_path,original_language, target_language)
# translated_text_file = translator.transcribe_and_translate()
# return translated_text_file
# interface_text_file = gr.Interface(
# fn=app,
# inputs=[
# gr.File(label="Upload Text File"),
# gr.Dropdown(["English", "German", "French", "Spanish"], label="Original Language"),
# gr.Dropdown(["English", "German", "French", "Spanish", "Urdu"], label="Targeted Language"),
# ],
# outputs=[gr.File(label="Translated Text File")],
# )
# interface_text_file.launch(debug=True)
# interface = gr.Interface(
# fn=app,
# inputs=[
# gr.components.Video(sources="upload", label="upload video"),
# gr.Dropdown(
# ["English", "German", "French" ,"Spanish"], label="Original Language"
# ),
# gr.Dropdown(
# ["English", "German", "French" ,"Spanish","Urdu"], label="Targeted Language"
# )
# # gr.components.Textbox(label="Enter Float Value")
# ],
# outputs=outputs=[gr.components.Textbox(label="your result")]
# # outputs=[gr.components.File(label="Your result")]
# )
# interface.launch(debug=True)