lodhrangpt commited on
Commit
cac2c45
·
verified ·
1 Parent(s): 0e511f7

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
+ import requests
3
+
4
+ # Function to send audio to Groq API and get transcription
5
+ def transcribe(audio_path):
6
+ # Read audio file in binary mode
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(type="filepath"), # Removed 'source' parameter for compatibility
42
+ outputs="text",
43
+ title="Voice to Text Converter App",
44
+
45
+ )
46
+
47
+ iface.launch()