gladikos commited on
Commit
72eb52e
·
verified ·
1 Parent(s): 64a4b45

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Alle Sprachmodelle
5
+ translation_models = {
6
+ "Deutsch → Englisch": "Helsinki-NLP/opus-mt-de-en",
7
+ "Englisch → Deutsch": "Helsinki-NLP/opus-mt-en-de",
8
+ "Englisch → Französisch": "Helsinki-NLP/opus-mt-en-fr",
9
+ "Französisch → Englisch": "Helsinki-NLP/opus-mt-fr-en",
10
+ "Spanisch → Deutsch": "Helsinki-NLP/opus-mt-es-de",
11
+ "Deutsch → Spanisch": "Helsinki-NLP/opus-mt-de-es",
12
+ "Deutsch → Griechisch": "Helsinki-NLP/opus-mt-de-el",
13
+ "Griechisch → Deutsch": "Helsinki-NLP/opus-mt-el-de",
14
+ "Deutsch → Italienisch": "Helsinki-NLP/opus-mt-de-it",
15
+ "Italienisch → Deutsch": "Helsinki-NLP/opus-mt-it-de"
16
+ }
17
+
18
+ # Übersetzungsfunktion
19
+ def translate_audio(audio, text, language_pair):
20
+ model_name = translation_models[language_pair]
21
+ translator = pipeline("translation", model=model_name)
22
+
23
+ if audio is not None:
24
+ text = audio["text"]
25
+
26
+ result = translator(text, max_length=512)
27
+ translated_text = result[0]['translation_text']
28
+ return translated_text, translated_text
29
+
30
+ # Gradio Interface
31
+ iface = gr.Interface(
32
+ fn=translate_audio,
33
+ inputs=[
34
+ gr.Audio(source="microphone", type="filepath", label="🎤 Spracheingabe (optional)"),
35
+ gr.Textbox(lines=4, label="✍️ Oder Text eingeben"),
36
+ gr.Dropdown(choices=list(translation_models.keys()), label="🌐 Sprachrichtung wählen")
37
+ ],
38
+ outputs=[
39
+ gr.Textbox(label="📝 Übersetzter Text"),
40
+ gr.Audio(label="🔊 Gesprochene Ausgabe", type="auto")
41
+ ],
42
+ title="🌍 Multilinguale Übersetzer-App",
43
+ description="Wähle eine Sprachrichtung, gib Text ein oder sprich etwas. Der Text wird übersetzt und vorgelesen.",
44
+ allow_flagging="never"
45
+ )
46
+
47
+ iface.launch()