Update app.py
Browse files
app.py
CHANGED
|
@@ -126,12 +126,18 @@ def translate_local(text_to_translate, target_lang='ta-IN', device=None):
|
|
| 126 |
|
| 127 |
translated_text = " ".join(translated_chunks)
|
| 128 |
|
| 129 |
-
def main_run(video_path):
|
| 130 |
original_audio_file = extract_audio_from_video(video_path)
|
| 131 |
original_text = transcribe_audio(original_audio_file)
|
| 132 |
-
translated_text = translate_local(original_text)
|
| 133 |
return translated_text
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
# --- Gradio Interface Definition ---
|
| 136 |
# Title and description for the new Space
|
| 137 |
title = "Custom Whisper Transcription App"
|
|
@@ -147,16 +153,51 @@ article = "<p style='text-align: center'><a href='https://huggingface.co/openai/
|
|
| 147 |
# We define the input as an Audio component and the output as a Textbox
|
| 148 |
app_interface = gr.Interface(
|
| 149 |
fn=main_run,
|
| 150 |
-
inputs=gr.Video(
|
| 151 |
-
|
| 152 |
-
),
|
| 153 |
-
outputs=gr.Textbox(label="Translation Result"),
|
| 154 |
title=title,
|
| 155 |
description=description,
|
| 156 |
article=article,
|
| 157 |
allow_flagging="never"
|
| 158 |
)
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
# --- Launch the App ---
|
| 161 |
if __name__ == "__main__":
|
| 162 |
# The launch() method creates a web server and makes the interface accessible.
|
|
|
|
| 126 |
|
| 127 |
translated_text = " ".join(translated_chunks)
|
| 128 |
|
| 129 |
+
def main_run(video_path,target_lang):
|
| 130 |
original_audio_file = extract_audio_from_video(video_path)
|
| 131 |
original_text = transcribe_audio(original_audio_file)
|
| 132 |
+
translated_text = translate_local(original_text,target_lang)
|
| 133 |
return translated_text
|
| 134 |
+
|
| 135 |
+
def audio_pipeline_run(audio_path,target_lang):
|
| 136 |
+
original_text = transcribe_audio(audio_path)
|
| 137 |
+
translated_text = translate_local(original_text,target_lang)
|
| 138 |
+
return translated_text
|
| 139 |
+
|
| 140 |
+
|
| 141 |
# --- Gradio Interface Definition ---
|
| 142 |
# Title and description for the new Space
|
| 143 |
title = "Custom Whisper Transcription App"
|
|
|
|
| 153 |
# We define the input as an Audio component and the output as a Textbox
|
| 154 |
app_interface = gr.Interface(
|
| 155 |
fn=main_run,
|
| 156 |
+
inputs=gr.Video(label="Upload Video"),gr.
|
| 157 |
+
outputs=gr.Textbox(label="Translation Result"),gr.Radio(choices=["Tamil", "Telugu", "Hindi"], label="Target Language", value="Tamil")
|
|
|
|
|
|
|
| 158 |
title=title,
|
| 159 |
description=description,
|
| 160 |
article=article,
|
| 161 |
allow_flagging="never"
|
| 162 |
)
|
| 163 |
|
| 164 |
+
with gr.Blocks(theme=Soft(), title="Audio/Video Translation Toolkit") as ui:
|
| 165 |
+
gr.Markdown("# π Audio/Video Translation Toolkit")
|
| 166 |
+
with gr.Tabs():
|
| 167 |
+
with gr.Tab("π¬ Translate Video"):
|
| 168 |
+
with gr.Row():
|
| 169 |
+
with gr.Column():
|
| 170 |
+
video_in = gr.Video(label="Input Video", height=500)
|
| 171 |
+
lang_radio_vid = gr.Radio(choices=["Tamil", "Telugu", "Hindi"], label="Target Language", value="Tamil")
|
| 172 |
+
submit_btn_vid = gr.Button("Translate Video", variant="primary")
|
| 173 |
+
|
| 174 |
+
with gr.Column():
|
| 175 |
+
video_out = gr.Textbox(label="Translation")
|
| 176 |
+
|
| 177 |
+
'''
|
| 178 |
+
with gr.Column():
|
| 179 |
+
video_out = gr.Video(label="Output Video", interactive=False, height=500)
|
| 180 |
+
'''
|
| 181 |
+
|
| 182 |
+
submit_btn_vid.click(fn=main_run, inputs=[video_in, lang_radio_vid], outputs=[video_out])
|
| 183 |
+
|
| 184 |
+
with gr.Tab("π΅ Translate Audio"):
|
| 185 |
+
with gr.Row():
|
| 186 |
+
with gr.Column():
|
| 187 |
+
audio_in_pipe = gr.Audio(type="filepath", label="Input Audio")
|
| 188 |
+
lang_radio_aud = gr.Radio(choices=["Tamil", "Telugu", "Hindi"], label="Target Language", value="Tamil")
|
| 189 |
+
submit_btn_aud = gr.Button("Translate Audio", variant="primary")
|
| 190 |
+
|
| 191 |
+
with gr.Column():
|
| 192 |
+
audio_out_pipe = gr.Textbox(label="Translation")
|
| 193 |
+
|
| 194 |
+
'''
|
| 195 |
+
with gr.Column():
|
| 196 |
+
audio_out_pipe = gr.Audio(label="Output Audio", interactive=False)
|
| 197 |
+
'''
|
| 198 |
+
|
| 199 |
+
submit_btn_aud.click(fn=audio_pipeline_run, inputs=[audio_in_pipe, lang_radio_aud], outputs=[audio_out_pipe])
|
| 200 |
+
|
| 201 |
# --- Launch the App ---
|
| 202 |
if __name__ == "__main__":
|
| 203 |
# The launch() method creates a web server and makes the interface accessible.
|