eaglelandsonce commited on
Commit
8b593b6
·
1 Parent(s): 8f5bff6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
-
2
  import openai
3
  import os
4
  import base64
@@ -41,12 +41,17 @@ def chat_with_model(prompt, document_section):
41
  return response
42
  #return response['choices'][0]['message']['content']
43
 
44
- def transcribe_audio(file_path, model):
 
 
 
 
 
45
 
46
  with open(file_path, 'rb') as f:
47
  data = {'file': f}
48
  # check for correctness - lively addition
49
- response = requests.post(openai.api_key, files=data, data={'model': model})
50
  if response.status_code == 200:
51
  st.write(response.json())
52
  response2 = chat_with_model(response.json().get('text'), '')
@@ -106,12 +111,11 @@ def get_table_download_link(file_path):
106
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
107
  return href
108
 
109
-
110
 
111
  # Audio, transcribe, GPT:
112
  filename = save_and_play_audio(audio_recorder)
113
  if filename is not None:
114
- transcription = transcribe_audio(filename, "whisper-1")
115
  st.write(transcription)
116
  gptOutput = chat_with_model(transcription, '') # push transcript through as prompt
117
  filename = generate_filename(transcription, choice)
 
1
+ # imports go here
2
  import openai
3
  import os
4
  import base64
 
41
  return response
42
  #return response['choices'][0]['message']['content']
43
 
44
+ def transcribe_audio(openai_key, file_path, model):
45
+
46
+ OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
47
+ headers = {
48
+ "Authorization": f"Bearer {openai_key}",
49
+ }
50
 
51
  with open(file_path, 'rb') as f:
52
  data = {'file': f}
53
  # check for correctness - lively addition
54
+ response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
55
  if response.status_code == 200:
56
  st.write(response.json())
57
  response2 = chat_with_model(response.json().get('text'), '')
 
111
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
112
  return href
113
 
 
114
 
115
  # Audio, transcribe, GPT:
116
  filename = save_and_play_audio(audio_recorder)
117
  if filename is not None:
118
+ transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
119
  st.write(transcription)
120
  gptOutput = chat_with_model(transcription, '') # push transcript through as prompt
121
  filename = generate_filename(transcription, choice)