File size: 1,576 Bytes
4e03ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d4ee50
 
4e03ccf
a1fa95b
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
import os
from groq import Groq

# Get API key from user input (hidden)
api_key = gr.Textbox(label="Enter Your Groq API Key", type="password")

def transcribe_audio(api_key, audio_file=None):
    client = Groq(api_key=api_key)  # Initialize Groq client with user-provided key

    if audio_file is not None:
        with open(audio_file.name, "rb") as file:
            transcription = client.audio.transcriptions.create(
                file=(audio_file.name, file.read()),
                model="whisper-large-v3",
                temperature=1,
                response_format="verbose_json",
            )
        return transcription.text
    else:
        return "No audio file provided."

# Interface for audio file upload and transcription
demo = gr.Interface(
    fn=transcribe_audio,
    inputs=[
        api_key,  # Add API key input
        gr.File(label="Upload Audio File"),
    ],
    outputs=gr.Textbox(label="Transcribed Text"),
    title="Audio Transcription HNM",
    description="Upload an audio file to transcribe it into text",
)

if __name__ == "__main__":
    demo.launch()

"""
## How to use this app:
1. Enter your [Groq API Key](https://console.groq.com/keys) in the provided field.
2. Click on the upload section and provide a supported audio file. Supported audio files include mp3, mp4, mpeg, mpga, m4a, wav, and webm file types.
3. Click the "Process" button to transcribe your speech and generate a response from our AI assistant.
4. The transcription and AI assistant response will appear in the respective text boxes.
"""