tsi-org's picture
Update app.py
5b71105 verified
import gradio as gr
import os
from groq import Groq
# Predefined password
CORRECT_PASSWORD = "password123"
# Get the Groq API key from the environment variable
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
def check_password(password):
return password == CORRECT_PASSWORD
def transcribe_audio(password, audio_file):
if not check_password(password):
return "Incorrect password. Access denied."
if not audio_file:
return "Please provide an audio file."
if not GROQ_API_KEY:
return "Groq API key not found in environment variables."
try:
client = Groq(api_key=GROQ_API_KEY)
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
except Exception as e:
return f"An error occurred: {str(e)}"
iface = gr.Interface(
fn=transcribe_audio,
inputs=[
gr.Textbox(type="password", label="Password"),
gr.File(label="Upload Audio File")
],
outputs=gr.Textbox(label="Result"),
title="Password Protected Audio Transcription App",
description="Enter the correct password to access the app. Then upload an audio file to transcribe."
)
if __name__ == "__main__":
iface.launch(share=True)