File size: 898 Bytes
2e1f2f2
92d58b3
2e1f2f2
 
 
5ad6afe
2e1f2f2
 
5ad6afe
2e1f2f2
36facce
92d58b3
 
2e1f2f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr
import os
import deepl
import openai

TARGET_LANG = "EN-GB"
deepl_key = os.environ.get('DEEPL')

translator = deepl.Translator(deepl_key)
pipe = pipeline(model="torileatherman/train_first_try")  # change to "your-username/the-name-you-picked"

def transcribe(audio):
    text_sv = pipe(audio)["text"]
    print(f"Audio transcribed: {text_sv}")
    text_en = translator.translate_text(text_sv, target_lang=TARGET_LANG).text
    print(f"Text translated: {text_en}")
    return text_sv, text_en

iface = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(source="microphone", type="filepath"),
    outputs=[gr.Textbox(label="Transcribed text"),
             gr.Textbox(label="English translation")],
    title="Swedish speech to english text",
    description="Transcribing swedish speech to text and translating to english!",
)

iface.launch()