bai4578 commited on
Commit
8fc32d0
·
verified ·
1 Parent(s): d550519

Update app.py

Browse files

first to try adding password

Files changed (1) hide show
  1. app.py +75 -40
app.py CHANGED
@@ -167,6 +167,12 @@ import shutil
167
  # Initialize the Groq client
168
  client = Groq(api_key=os.environ["keko"])
169
 
 
 
 
 
 
 
170
  def save_audio(audio_file):
171
  if audio_file is None:
172
  return None, "No audio file provided."
@@ -219,50 +225,79 @@ def generate_text(text, prompt_type):
219
 
220
  return response.choices[0].message.content
221
 
 
 
 
 
222
  # Create the Gradio interface using Blocks
223
  with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
224
  gr.Markdown("# Audio Recorder, Transcriber, and Text Generator")
225
- gr.Markdown("Record audio, transcribe it, and optionally generate text based on the transcription.")
226
-
227
- with gr.Row():
228
- audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Record or Upload Audio")
229
-
230
- with gr.Row():
231
- save_btn = gr.Button("Save Audio")
232
- transcribe_btn = gr.Button("Transcribe Audio")
233
-
234
- with gr.Row():
235
- audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
236
- save_msg = gr.Textbox(label="Save Status")
237
-
238
- transcription_output = gr.Textbox(label="Transcription", show_copy_button=True)
239
-
240
- with gr.Row():
241
- prompt_type = gr.Dropdown(
242
- choices=["dic_clean","summarize", "create_qa", "analyze"],
243
- label="Select Text Generation Type",
244
- value="dic_clean"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  )
246
- generate_btn = gr.Button("Generate Text")
247
-
248
- generated_text_output = gr.Textbox(label="Generated Text", show_copy_button=True)
249
-
250
- save_btn.click(
251
- save_audio,
252
- inputs=[audio_input],
253
- outputs=[audio_output, save_msg]
254
- )
255
-
256
- transcribe_btn.click(
257
- transcribe_audio,
258
- inputs=[audio_input],
259
- outputs=[transcription_output]
260
- )
261
-
262
- generate_btn.click(
263
- generate_text,
264
- inputs=[transcription_output, prompt_type],
265
- outputs=[generated_text_output]
 
 
 
 
 
 
 
 
 
266
  )
267
 
268
  # Launch the interface
 
167
  # Initialize the Groq client
168
  client = Groq(api_key=os.environ["keko"])
169
 
170
+ def check_password(password):
171
+ correct_password = "zoo" # Set your desired password here
172
+ return password == correct_password
173
+
174
+
175
+
176
  def save_audio(audio_file):
177
  if audio_file is None:
178
  return None, "No audio file provided."
 
225
 
226
  return response.choices[0].message.content
227
 
228
+
229
+
230
+
231
+
232
  # Create the Gradio interface using Blocks
233
  with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
234
  gr.Markdown("# Audio Recorder, Transcriber, and Text Generator")
235
+ gr.Markdown("Enter the correct password to access the application.")
236
+
237
+ password_input = gr.Textbox(type="password", label="Enter Password")
238
+ login_button = gr.Button("Login")
239
+ login_message = gr.Markdown()
240
+
241
+ with gr.Column(visible=False) as main_interface:
242
+ gr.Markdown("Record audio, transcribe it, and optionally generate text based on the transcription.")
243
+
244
+ with gr.Row():
245
+ audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Record or Upload Audio")
246
+
247
+ with gr.Row():
248
+ save_btn = gr.Button("Save Audio")
249
+ transcribe_btn = gr.Button("Transcribe Audio")
250
+
251
+ with gr.Row():
252
+ audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
253
+ save_msg = gr.Textbox(label="Save Status")
254
+
255
+ transcription_output = gr.Textbox(label="Transcription", show_copy_button=True)
256
+
257
+ with gr.Row():
258
+ prompt_type = gr.Dropdown(
259
+ choices=["dic_clean","summarize", "create_qa", "analyze"],
260
+ label="Select Text Generation Type",
261
+ value="dic_clean"
262
+ )
263
+ generate_btn = gr.Button("Generate Text")
264
+
265
+ generated_text_output = gr.Textbox(label="Generated Text", show_copy_button=True)
266
+
267
+ save_btn.click(
268
+ save_audio,
269
+ inputs=[audio_input],
270
+ outputs=[audio_output, save_msg]
271
  )
272
+
273
+ transcribe_btn.click(
274
+ transcribe_audio,
275
+ inputs=[audio_input],
276
+ outputs=[transcription_output]
277
+ )
278
+
279
+ generate_btn.click(
280
+ generate_text,
281
+ inputs=[transcription_output, prompt_type],
282
+ outputs=[generated_text_output]
283
+ )
284
+
285
+ def login(password):
286
+ if check_password(password):
287
+ return {
288
+ main_interface: gr.Column(visible=True),
289
+ login_message: gr.Markdown("Login successful. You can now use the application.")
290
+ }
291
+ else:
292
+ return {
293
+ main_interface: gr.Column(visible=False),
294
+ login_message: gr.Markdown("Incorrect password. Please try again.")
295
+ }
296
+
297
+ login_button.click(
298
+ login,
299
+ inputs=[password_input],
300
+ outputs=[main_interface, login_message]
301
  )
302
 
303
  # Launch the interface