Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,9 +31,9 @@ from htmlTemplates import css, bot_template, user_template
|
|
31 |
|
32 |
def generate_filename(prompt, file_type):
|
33 |
central = pytz.timezone('US/Central')
|
34 |
-
safe_date_time = datetime.now(central).strftime("%m%d_%I%M")
|
35 |
-
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45]
|
36 |
-
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
37 |
|
38 |
def transcribe_audio(openai_key, file_path, model):
|
39 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
@@ -45,12 +45,13 @@ def transcribe_audio(openai_key, file_path, model):
|
|
45 |
response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
|
46 |
if response.status_code == 200:
|
47 |
st.write(response.json())
|
48 |
-
|
49 |
-
|
50 |
st.write('Responses:')
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
else:
|
55 |
st.write(response.json())
|
56 |
st.error("Error in API call.")
|
@@ -215,13 +216,6 @@ def process_user_input(user_question):
|
|
215 |
for i, message in enumerate(st.session_state.chat_history):
|
216 |
template = user_template if i % 2 == 0 else bot_template
|
217 |
st.write(template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
|
226 |
def main():
|
227 |
# Sidebar and global
|
@@ -235,10 +229,9 @@ def main():
|
|
235 |
filename = save_and_play_audio(audio_recorder)
|
236 |
if filename is not None:
|
237 |
transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
|
238 |
-
|
239 |
-
|
240 |
-
filename
|
241 |
-
create_file(filename, transcription, gptOutput)
|
242 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
243 |
|
244 |
|
|
|
31 |
|
32 |
def generate_filename(prompt, file_type):
|
33 |
central = pytz.timezone('US/Central')
|
34 |
+
safe_date_time = datetime.now(central).strftime("%m%d_%I%M") # Date and time DD-TT
|
35 |
+
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45] # Limit file name size and trim whitespace
|
36 |
+
return f"{safe_date_time}_{safe_prompt}.{file_type}" # Return a safe file name
|
37 |
|
38 |
def transcribe_audio(openai_key, file_path, model):
|
39 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
|
|
45 |
response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
|
46 |
if response.status_code == 200:
|
47 |
st.write(response.json())
|
48 |
+
chatResponse = chat_with_model(response.json().get('text'), '') # *************************************
|
49 |
+
transcript = response.json().get('text')
|
50 |
st.write('Responses:')
|
51 |
+
st.write(chatResponse)
|
52 |
+
filename = generate_filename(transcript, 'txt')
|
53 |
+
create_file(filename, transcript, chatResponse)
|
54 |
+
return transcript
|
55 |
else:
|
56 |
st.write(response.json())
|
57 |
st.error("Error in API call.")
|
|
|
216 |
for i, message in enumerate(st.session_state.chat_history):
|
217 |
template = user_template if i % 2 == 0 else bot_template
|
218 |
st.write(template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
def main():
|
221 |
# Sidebar and global
|
|
|
229 |
filename = save_and_play_audio(audio_recorder)
|
230 |
if filename is not None:
|
231 |
transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
|
232 |
+
#gptOutput = chat_with_model(transcription, '', model_choice) # *************************************
|
233 |
+
#filename = generate_filename(transcription, choice)
|
234 |
+
#create_file(filename, transcription, gptOutput)
|
|
|
235 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
236 |
|
237 |
|