Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
from audio_recorder_streamlit import audio_recorder
|
3 |
-
|
4 |
API_KEY = 'enter-openai-api-key-here'
|
5 |
|
6 |
|
7 |
|
8 |
def transcribe_text_to_voice(audio_location):
|
9 |
-
client =
|
10 |
audio_file= open(audio_location, "rb")
|
11 |
transcript = client.audio.transcriptions.create(model="whisper-1", file=audio_file)
|
12 |
return transcript.text
|
13 |
|
14 |
def chat_completion_call(text):
|
15 |
-
client =
|
16 |
messages = [{"role": "user", "content": text}]
|
17 |
response = client.chat.completions.create(model="gpt-3.5-turbo-1106", messages=messages)
|
18 |
return response.choices[0].message.content
|
19 |
|
20 |
|
21 |
def text_to_speech_ai(speech_file_path, api_response):
|
22 |
-
client =
|
23 |
response = client.audio.speech.create(model="tts-1",voice="nova",input=api_response)
|
24 |
response.stream_to_file(speech_file_path)
|
25 |
|
|
|
1 |
import streamlit as st
|
2 |
from audio_recorder_streamlit import audio_recorder
|
3 |
+
import openai
|
4 |
API_KEY = 'enter-openai-api-key-here'
|
5 |
|
6 |
|
7 |
|
8 |
def transcribe_text_to_voice(audio_location):
|
9 |
+
client = openai(api_key=API_KEY)
|
10 |
audio_file= open(audio_location, "rb")
|
11 |
transcript = client.audio.transcriptions.create(model="whisper-1", file=audio_file)
|
12 |
return transcript.text
|
13 |
|
14 |
def chat_completion_call(text):
|
15 |
+
client = openai(api_key=API_KEY)
|
16 |
messages = [{"role": "user", "content": text}]
|
17 |
response = client.chat.completions.create(model="gpt-3.5-turbo-1106", messages=messages)
|
18 |
return response.choices[0].message.content
|
19 |
|
20 |
|
21 |
def text_to_speech_ai(speech_file_path, api_response):
|
22 |
+
client = openai(api_key=API_KEY)
|
23 |
response = client.audio.speech.create(model="tts-1",voice="nova",input=api_response)
|
24 |
response.stream_to_file(speech_file_path)
|
25 |
|