Update app.py
Browse files
app.py
CHANGED
|
@@ -95,19 +95,15 @@ def pdf_chat(pdf_file, text_query, temperature, top_p, max_output_tokens):
|
|
| 95 |
return query_openai(messages, temperature, top_p, max_output_tokens)
|
| 96 |
|
| 97 |
# Function to transcribe audio to text using OpenAI Whisper API
|
| 98 |
-
def transcribe_audio(
|
| 99 |
if not openai_api_key:
|
| 100 |
return "Error: No API key provided."
|
| 101 |
|
| 102 |
openai.api_key = openai_api_key
|
| 103 |
|
| 104 |
try:
|
| 105 |
-
# Open the audio file and pass it as a file object
|
| 106 |
-
with open(audio, 'rb') as audio_file:
|
| 107 |
-
audio_file_content = audio_file.read()
|
| 108 |
-
|
| 109 |
# Use the correct transcription API call
|
| 110 |
-
audio_file_obj = io.BytesIO(
|
| 111 |
audio_file_obj.name = 'audio.wav' # Set a name for the file object (as OpenAI expects it)
|
| 112 |
|
| 113 |
# Transcribe the audio to text using OpenAI's whisper model
|
|
@@ -185,8 +181,8 @@ with gr.Blocks() as demo:
|
|
| 185 |
|
| 186 |
# For Voice Chat
|
| 187 |
audio_button.click(
|
| 188 |
-
lambda
|
| 189 |
-
[{"role": "user", "content": [{"type": "text", "text": transcribe_audio(
|
| 190 |
temperature, top_p, max_output_tokens
|
| 191 |
), [audio_upload, audio_query, temperature, top_p, max_output_tokens], audio_output
|
| 192 |
)
|
|
|
|
| 95 |
return query_openai(messages, temperature, top_p, max_output_tokens)
|
| 96 |
|
| 97 |
# Function to transcribe audio to text using OpenAI Whisper API
|
| 98 |
+
def transcribe_audio(audio_binary, openai_api_key):
|
| 99 |
if not openai_api_key:
|
| 100 |
return "Error: No API key provided."
|
| 101 |
|
| 102 |
openai.api_key = openai_api_key
|
| 103 |
|
| 104 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Use the correct transcription API call
|
| 106 |
+
audio_file_obj = io.BytesIO(audio_binary)
|
| 107 |
audio_file_obj.name = 'audio.wav' # Set a name for the file object (as OpenAI expects it)
|
| 108 |
|
| 109 |
# Transcribe the audio to text using OpenAI's whisper model
|
|
|
|
| 181 |
|
| 182 |
# For Voice Chat
|
| 183 |
audio_button.click(
|
| 184 |
+
lambda audio_binary, query, temperature, top_p, max_output_tokens: query_openai(
|
| 185 |
+
[{"role": "user", "content": [{"type": "text", "text": transcribe_audio(audio_binary, api_key)}, {"type": "text", "text": query}]}],
|
| 186 |
temperature, top_p, max_output_tokens
|
| 187 |
), [audio_upload, audio_query, temperature, top_p, max_output_tokens], audio_output
|
| 188 |
)
|