Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
from groq import Groq
|
4 |
import soundfile as sf
|
5 |
from tempfile import NamedTemporaryFile
|
|
|
6 |
|
7 |
# Load the API key from the environment variable
|
8 |
api_key = os.getenv('groqwhisper')
|
@@ -38,30 +39,27 @@ def processaudio(audio_data):
|
|
38 |
except Exception as e:
|
39 |
return f"Ein Fehler ist aufgetreten: {str(e)}"
|
40 |
|
41 |
-
def process_audio(file_path):
|
42 |
-
try:
|
43 |
-
# Open the audio file
|
44 |
-
with open(file_path, "rb") as file:
|
45 |
-
# Create a transcription of the audio file
|
46 |
-
transcription = client.audio.transcriptions.create(
|
47 |
-
file=(os.path.basename(file_path), file.read()), # Correct passing of filename
|
48 |
-
model="whisper-large-v3-turbo", # Required model to use for transcription
|
49 |
-
prompt="transcribe", # Optional
|
50 |
-
language="de", # Optional
|
51 |
-
response_format="json", # Optional
|
52 |
-
temperature=0.0 # Optional
|
53 |
-
)
|
54 |
-
# Return the transcription text
|
55 |
-
return transcription.text
|
56 |
-
except Exception as e:
|
57 |
-
return f"Ein Fehler ist aufgetreten: {str(e)}"
|
58 |
-
|
59 |
# Streamlit Interface
|
60 |
st.title("Audio Transkription")
|
61 |
-
sr_outputs = st.empty()
|
62 |
-
sr_inputs = st.file_uploader("Laden Sie eine Audiodatei hoch", type=["wav", "mp3"])
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
transcription = processaudio(audio_data)
|
67 |
sr_outputs.text(transcription)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from groq import Groq
|
4 |
import soundfile as sf
|
5 |
from tempfile import NamedTemporaryFile
|
6 |
+
import io # Für Bytes-IO hinzugefügt
|
7 |
|
8 |
# Load the API key from the environment variable
|
9 |
api_key = os.getenv('groqwhisper')
|
|
|
39 |
except Exception as e:
|
40 |
return f"Ein Fehler ist aufgetreten: {str(e)}"
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Streamlit Interface
|
43 |
st.title("Audio Transkription")
|
44 |
+
sr_outputs = st.empty()
|
|
|
45 |
|
46 |
+
# Dateiupload und Mikrofonaufnahme als getrennte Eingaben
|
47 |
+
uploaded_file = st.file_uploader("Laden Sie eine Audiodatei hoch", type=["wav", "mp3"])
|
48 |
+
audio_bytes = st.audio_input("Oder sprechen Sie jetzt:", type="wav")
|
49 |
+
|
50 |
+
if uploaded_file:
|
51 |
+
# Verarbeitung hochgeladener Datei
|
52 |
+
audio_data = sf.read(uploaded_file)
|
53 |
transcription = processaudio(audio_data)
|
54 |
sr_outputs.text(transcription)
|
55 |
+
|
56 |
+
elif audio_bytes:
|
57 |
+
# Verarbeitung Mikrofonaufnahme
|
58 |
+
try:
|
59 |
+
# Konvertiere Bytes in Audio-Daten
|
60 |
+
audio_io = io.BytesIO(audio_bytes)
|
61 |
+
audio_data = sf.read(audio_io)
|
62 |
+
transcription = processaudio(audio_data)
|
63 |
+
sr_outputs.text(transcription)
|
64 |
+
except Exception as e:
|
65 |
+
sr_outputs.text(f"Fehler bei der Aufnahmeverarbeitung: {str(e)}")
|