Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,7 @@ client = Groq(api_key=api_key)
|
|
17 |
|
18 |
def process_audio(audio_bytes):
|
19 |
"""Verarbeitet Audio-Bytes und gibt Transkript zurück"""
|
|
|
20 |
try:
|
21 |
# Konvertiere Bytes in Audio-Daten
|
22 |
audio_io = io.BytesIO(audio_bytes)
|
@@ -27,7 +28,7 @@ def process_audio(audio_bytes):
|
|
27 |
|
28 |
with open(tmpfile.name, "rb") as audio_file:
|
29 |
transcription = client.audio.transcriptions.create(
|
30 |
-
file=(tmpfile.name, audio_file,
|
31 |
model="whisper-large-v3-turbo",
|
32 |
language="de",
|
33 |
response_format="text"
|
@@ -37,25 +38,36 @@ def process_audio(audio_bytes):
|
|
37 |
except Exception as e:
|
38 |
return f"Fehler: {str(e)}"
|
39 |
finally:
|
40 |
-
if
|
41 |
os.unlink(tmpfile.name)
|
42 |
|
43 |
# Streamlit UI
|
44 |
st.title("🎤 Audio Transkription")
|
45 |
st.info("Funktioniert auf Hugging Face Spaces!")
|
46 |
-
#sr_outputs = st.text
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
)
|
51 |
|
52 |
-
if
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def process_audio(audio_bytes):
|
19 |
"""Verarbeitet Audio-Bytes und gibt Transkript zurück"""
|
20 |
+
tmpfile = None # Initialisierung für finally-Block
|
21 |
try:
|
22 |
# Konvertiere Bytes in Audio-Daten
|
23 |
audio_io = io.BytesIO(audio_bytes)
|
|
|
28 |
|
29 |
with open(tmpfile.name, "rb") as audio_file:
|
30 |
transcription = client.audio.transcriptions.create(
|
31 |
+
file=(os.path.basename(tmpfile.name), audio_file), # Korrigierte Parameter
|
32 |
model="whisper-large-v3-turbo",
|
33 |
language="de",
|
34 |
response_format="text"
|
|
|
38 |
except Exception as e:
|
39 |
return f"Fehler: {str(e)}"
|
40 |
finally:
|
41 |
+
if tmpfile and os.path.exists(tmpfile.name):
|
42 |
os.unlink(tmpfile.name)
|
43 |
|
44 |
# Streamlit UI
|
45 |
st.title("🎤 Audio Transkription")
|
46 |
st.info("Funktioniert auf Hugging Face Spaces!")
|
|
|
47 |
|
48 |
+
# Kombinierter Uploader für Datei und Mikrofon
|
49 |
+
audio_file = st.file_uploader(
|
50 |
+
"Aufnahme starten oder Datei hochladen",
|
51 |
+
type=["wav"],
|
52 |
+
accept_multiple_files=False,
|
53 |
+
help="Klicken Sie auf 'Browse Files' und wählen Sie im Browser 'Take a recording'"
|
54 |
)
|
55 |
|
56 |
+
if audio_file:
|
57 |
+
with st.spinner("Verarbeite Audio..."):
|
58 |
+
try:
|
59 |
+
# Datei in Bytes lesen
|
60 |
+
audio_bytes = audio_file.read()
|
61 |
+
|
62 |
+
# Transkription durchführen
|
63 |
+
result = process_audio(audio_bytes)
|
64 |
+
|
65 |
+
# Ergebnis anzeigen
|
66 |
+
st.subheader("Transkription:")
|
67 |
+
st.success(result)
|
68 |
+
|
69 |
+
# Audio-Player anzeigen
|
70 |
+
st.audio(audio_bytes, format="audio/wav")
|
71 |
+
|
72 |
+
except Exception as e:
|
73 |
+
st.error(f"Fehler: {str(e)}")
|