Update app.py
Browse files
app.py
CHANGED
|
@@ -5,18 +5,24 @@ from groq import Groq
|
|
| 5 |
# Predefined password
|
| 6 |
CORRECT_PASSWORD = "password123"
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
def check_password(password):
|
| 9 |
return password == CORRECT_PASSWORD
|
| 10 |
|
| 11 |
-
def transcribe_audio(password,
|
| 12 |
if not check_password(password):
|
| 13 |
return "Incorrect password. Access denied."
|
| 14 |
|
| 15 |
-
if not
|
| 16 |
-
return "Please provide
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
client = Groq(api_key=
|
| 20 |
with open(audio_file.name, "rb") as file:
|
| 21 |
transcription = client.audio.transcriptions.create(
|
| 22 |
file=(audio_file.name, file.read()),
|
|
@@ -32,12 +38,11 @@ iface = gr.Interface(
|
|
| 32 |
fn=transcribe_audio,
|
| 33 |
inputs=[
|
| 34 |
gr.Textbox(type="password", label="Password"),
|
| 35 |
-
gr.Textbox(label="Groq API Key", type="password"),
|
| 36 |
gr.File(label="Upload Audio File")
|
| 37 |
],
|
| 38 |
outputs=gr.Textbox(label="Result"),
|
| 39 |
title="Password Protected Audio Transcription App",
|
| 40 |
-
description="Enter the correct password to access the app. Then
|
| 41 |
)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
|
|
|
| 5 |
# Predefined password
|
| 6 |
CORRECT_PASSWORD = "password123"
|
| 7 |
|
| 8 |
+
# Get the Groq API key from the environment variable
|
| 9 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 10 |
+
|
| 11 |
def check_password(password):
|
| 12 |
return password == CORRECT_PASSWORD
|
| 13 |
|
| 14 |
+
def transcribe_audio(password, audio_file):
|
| 15 |
if not check_password(password):
|
| 16 |
return "Incorrect password. Access denied."
|
| 17 |
|
| 18 |
+
if not audio_file:
|
| 19 |
+
return "Please provide an audio file."
|
| 20 |
+
|
| 21 |
+
if not GROQ_API_KEY:
|
| 22 |
+
return "Groq API key not found in environment variables."
|
| 23 |
|
| 24 |
try:
|
| 25 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 26 |
with open(audio_file.name, "rb") as file:
|
| 27 |
transcription = client.audio.transcriptions.create(
|
| 28 |
file=(audio_file.name, file.read()),
|
|
|
|
| 38 |
fn=transcribe_audio,
|
| 39 |
inputs=[
|
| 40 |
gr.Textbox(type="password", label="Password"),
|
|
|
|
| 41 |
gr.File(label="Upload Audio File")
|
| 42 |
],
|
| 43 |
outputs=gr.Textbox(label="Result"),
|
| 44 |
title="Password Protected Audio Transcription App",
|
| 45 |
+
description="Enter the correct password to access the app. Then upload an audio file to transcribe."
|
| 46 |
)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|