Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,27 +7,38 @@ def transcribe(audio_path):
|
|
7 |
with open(audio_path, "rb") as audio_file:
|
8 |
audio_data = audio_file.read()
|
9 |
|
10 |
-
#
|
11 |
-
groq_api_endpoint = "https://api.groq.com/
|
|
|
|
|
12 |
headers = {
|
13 |
-
"Authorization": "Bearer
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
# Send audio to Groq API
|
18 |
-
response = requests.post(groq_api_endpoint, headers=headers, data=
|
19 |
|
20 |
# Parse response
|
21 |
if response.status_code == 200:
|
22 |
result = response.json()
|
23 |
-
return result.get("
|
24 |
else:
|
25 |
return f"Error: {response.status_code}, {response.text}"
|
26 |
|
27 |
# Gradio interface
|
28 |
iface = gr.Interface(
|
29 |
fn=transcribe,
|
30 |
-
inputs=gr.Audio(type="filepath"),
|
31 |
outputs="text",
|
32 |
title="Voice to Text Converter",
|
33 |
description="Record your voice, and it will be transcribed into text using Groq API."
|
|
|
7 |
with open(audio_path, "rb") as audio_file:
|
8 |
audio_data = audio_file.read()
|
9 |
|
10 |
+
# Groq API endpoint for audio transcription
|
11 |
+
groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
|
12 |
+
|
13 |
+
# Replace 'YOUR_GROQ_API_KEY' with your actual Groq API key
|
14 |
headers = {
|
15 |
+
"Authorization": "Bearer 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",
|
16 |
+
}
|
17 |
+
|
18 |
+
# Prepare the files and data for the request
|
19 |
+
files = {
|
20 |
+
'file': ('audio.wav', audio_data, 'audio/wav'),
|
21 |
+
}
|
22 |
+
data = {
|
23 |
+
'model': 'whisper-large-v3-turbo', # Specify the model to use
|
24 |
+
'response_format': 'json', # Desired response format
|
25 |
+
'language': 'en', # Language of the audio
|
26 |
}
|
27 |
|
28 |
# Send audio to Groq API
|
29 |
+
response = requests.post(groq_api_endpoint, headers=headers, files=files, data=data)
|
30 |
|
31 |
# Parse response
|
32 |
if response.status_code == 200:
|
33 |
result = response.json()
|
34 |
+
return result.get("text", "No transcription available.")
|
35 |
else:
|
36 |
return f"Error: {response.status_code}, {response.text}"
|
37 |
|
38 |
# Gradio interface
|
39 |
iface = gr.Interface(
|
40 |
fn=transcribe,
|
41 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
42 |
outputs="text",
|
43 |
title="Voice to Text Converter",
|
44 |
description="Record your voice, and it will be transcribed into text using Groq API."
|