File size: 1,118 Bytes
4e03ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()