awacke1 commited on
Commit
48b0926
·
1 Parent(s): 9b9483a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -71,23 +71,26 @@ def transcribe_audio(openai_key, file_path, model):
71
  st.error("Error in API call.")
72
  return None
73
 
74
- def save_and_play_audio(audio_recorder):
75
- audio_bytes = st.sidebar.audio_recorder()
 
 
76
  if audio_bytes:
77
  filename = generate_filename("Recording", "wav")
78
  with open(filename, 'wb') as f:
79
  f.write(audio_bytes)
80
  st.audio(audio_bytes, format="audio/wav")
81
  return filename
82
- # Updated to call direct from transcription to chat inference.
83
- USEAUDIO=False
84
  if USEAUDIO:
85
- filename = save_and_play_audio(audio_recorder)
86
- if filename is not None:
87
- #if st.button("Transcribe"):
88
- transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
89
- st.markdown('### Transcription:')
90
- st.write(transcription)
 
 
91
 
92
  def truncate_document(document, length):
93
  return document[:length]
 
71
  st.error("Error in API call.")
72
  return None
73
 
74
+
75
+ # Updated to call direct from transcription to chat inference.
76
+ save_and_play_audio(audio_recorder):
77
+ audio_bytes = audio_recorder()
78
  if audio_bytes:
79
  filename = generate_filename("Recording", "wav")
80
  with open(filename, 'wb') as f:
81
  f.write(audio_bytes)
82
  st.audio(audio_bytes, format="audio/wav")
83
  return filename
84
+ USEAUDIO=True
 
85
  if USEAUDIO:
86
+ if st.sidebar.checkbox('Use Audio Input'):
87
+ filename = save_and_play_audio(audio_recorder)
88
+ if filename is not None:
89
+ #if st.button("Transcribe"):
90
+ transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
91
+ st.markdown('### Transcription:')
92
+ st.write(transcription)
93
+
94
 
95
  def truncate_document(document, length):
96
  return document[:length]