tsi-org commited on
Commit
5b71105
·
verified ·
1 Parent(s): c2c2101

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
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, api_key, audio_file):
12
  if not check_password(password):
13
  return "Incorrect password. Access denied."
14
 
15
- if not api_key or not audio_file:
16
- return "Please provide both API key and audio file."
 
 
 
17
 
18
  try:
19
- client = Groq(api_key=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 provide your Groq API key and upload an audio file to transcribe."
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__":