Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from groq import Groq
|
4 |
+
|
5 |
+
# Get API key from user input (hidden)
|
6 |
+
api_key = gr.Textbox(label="Enter Your Groq API Key", type="password")
|
7 |
+
|
8 |
+
def transcribe_audio(api_key, audio_file=None):
|
9 |
+
client = Groq(api_key=api_key) # Initialize Groq client with user-provided key
|
10 |
+
|
11 |
+
if audio_file is not None:
|
12 |
+
with open(audio_file.name, "rb") as file:
|
13 |
+
transcription = client.audio.transcriptions.create(
|
14 |
+
file=(audio_file.name, file.read()),
|
15 |
+
model="whisper-large-v3",
|
16 |
+
temperature=1,
|
17 |
+
response_format="verbose_json",
|
18 |
+
)
|
19 |
+
return transcription.text
|
20 |
+
else:
|
21 |
+
return "No audio file provided."
|
22 |
+
|
23 |
+
# Interface for audio file upload and transcription
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=transcribe_audio,
|
26 |
+
inputs=[
|
27 |
+
api_key, # Add API key input
|
28 |
+
gr.File(label="Upload Audio File"),
|
29 |
+
],
|
30 |
+
outputs=gr.Textbox(label="Transcribed Text"),
|
31 |
+
title="Audio Transcription HNM",
|
32 |
+
description="Upload an audio file to transcribe it into text",
|
33 |
+
)
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch()
|