Update app.py
Browse files
app.py
CHANGED
@@ -313,6 +313,55 @@ def extract_title(text):
|
|
313 |
title = re.sub(r'[^a-zA-Z0-9_\-]', ' ', text[-200:])
|
314 |
return title[-200:]
|
315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
#@st.cache_resource
|
317 |
def process_image(image_input, user_prompt):
|
318 |
SaveNewFile=True
|
@@ -392,47 +441,6 @@ def create_audio_file(filename, audio_data, should_save):
|
|
392 |
else:
|
393 |
st.warning("Audio file not saved.")
|
394 |
|
395 |
-
def process_audio(audio_input, text_input=''):
|
396 |
-
if audio_input:
|
397 |
-
transcription = client.audio.transcriptions.create(
|
398 |
-
model="whisper-1",
|
399 |
-
file=audio_input,
|
400 |
-
)
|
401 |
-
st.session_state.messages.append({"role": "user", "content": transcription.text})
|
402 |
-
with st.chat_message("assistant"):
|
403 |
-
st.markdown(transcription.text)
|
404 |
-
|
405 |
-
SpeechSynthesis(transcription.text)
|
406 |
-
filename = generate_filename(transcription.text, "wav")
|
407 |
-
|
408 |
-
create_audio_file(filename, audio_input, should_save)
|
409 |
-
|
410 |
-
#SpeechSynthesis(transcription.text)
|
411 |
-
|
412 |
-
filename = generate_filename(transcription.text, "md")
|
413 |
-
create_file(filename, transcription.text, transcription.text, should_save)
|
414 |
-
#st.markdown(response.choices[0].message.content)
|
415 |
-
|
416 |
-
def process_audio_for_video(video_input):
|
417 |
-
if video_input:
|
418 |
-
try:
|
419 |
-
transcription = client.audio.transcriptions.create(
|
420 |
-
model="whisper-1",
|
421 |
-
file=video_input,
|
422 |
-
)
|
423 |
-
response = client.chat.completions.create(
|
424 |
-
model=MODEL,
|
425 |
-
messages=[
|
426 |
-
{"role": "system", "content":"""You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."""},
|
427 |
-
{"role": "user", "content": [{"type": "text", "text": f"The audio transcription is: {transcription}"}],}
|
428 |
-
],
|
429 |
-
temperature=0,
|
430 |
-
)
|
431 |
-
st.markdown(response.choices[0].message.content)
|
432 |
-
return response.choices[0].message.content
|
433 |
-
except:
|
434 |
-
st.write('No transcript')
|
435 |
-
|
436 |
def save_video(video_file):
|
437 |
# Save the uploaded video file
|
438 |
with open(video_file.name, "wb") as f:
|
|
|
313 |
title = re.sub(r'[^a-zA-Z0-9_\-]', ' ', text[-200:])
|
314 |
return title[-200:]
|
315 |
|
316 |
+
def process_audio(audio_input, text_input=''):
|
317 |
+
if audio_input:
|
318 |
+
|
319 |
+
# Check type - if it is a file we need bytes
|
320 |
+
if isinstance(audio_input, str):
|
321 |
+
with open(audio_input, "rb") as file:
|
322 |
+
audio_input = file.read()
|
323 |
+
SaveNewFile=False # file is there and this is just prompt inference
|
324 |
+
st.write(audio_input)
|
325 |
+
|
326 |
+
transcription = client.audio.transcriptions.create(
|
327 |
+
model="whisper-1",
|
328 |
+
file=audio_input,
|
329 |
+
)
|
330 |
+
st.session_state.messages.append({"role": "user", "content": transcription.text})
|
331 |
+
with st.chat_message("assistant"):
|
332 |
+
st.markdown(transcription.text)
|
333 |
+
|
334 |
+
SpeechSynthesis(transcription.text)
|
335 |
+
filename = generate_filename(transcription.text, "wav")
|
336 |
+
|
337 |
+
create_audio_file(filename, audio_input, should_save)
|
338 |
+
|
339 |
+
#SpeechSynthesis(transcription.text)
|
340 |
+
|
341 |
+
filename = generate_filename(transcription.text, "md")
|
342 |
+
create_file(filename, transcription.text, transcription.text, should_save)
|
343 |
+
#st.markdown(response.choices[0].message.content)
|
344 |
+
|
345 |
+
def process_audio_for_video(video_input):
|
346 |
+
if video_input:
|
347 |
+
try:
|
348 |
+
transcription = client.audio.transcriptions.create(
|
349 |
+
model="whisper-1",
|
350 |
+
file=video_input,
|
351 |
+
)
|
352 |
+
response = client.chat.completions.create(
|
353 |
+
model=MODEL,
|
354 |
+
messages=[
|
355 |
+
{"role": "system", "content":"""You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."""},
|
356 |
+
{"role": "user", "content": [{"type": "text", "text": f"The audio transcription is: {transcription}"}],}
|
357 |
+
],
|
358 |
+
temperature=0,
|
359 |
+
)
|
360 |
+
st.markdown(response.choices[0].message.content)
|
361 |
+
return response.choices[0].message.content
|
362 |
+
except:
|
363 |
+
st.write('No transcript')
|
364 |
+
|
365 |
#@st.cache_resource
|
366 |
def process_image(image_input, user_prompt):
|
367 |
SaveNewFile=True
|
|
|
441 |
else:
|
442 |
st.warning("Audio file not saved.")
|
443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
def save_video(video_file):
|
445 |
# Save the uploaded video file
|
446 |
with open(video_file.name, "wb") as f:
|