Commit
•
f5f1842
1
Parent(s):
d415e7e
update the code to align with latest packages
Browse filesOn branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
modified: .gitignore
modified: app.py
modified: supplier.py
- .gitignore +1 -1
- app.py +6 -6
- supplier.py +29 -27
.gitignore
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# directories that are local to the server os
|
2 |
.archive
|
3 |
-
venv
|
4 |
__pycache__
|
5 |
|
6 |
# files local to the server os
|
|
|
1 |
# directories that are local to the server os
|
2 |
.archive
|
3 |
+
.venv
|
4 |
__pycache__
|
5 |
|
6 |
# files local to the server os
|
app.py
CHANGED
@@ -25,10 +25,10 @@ with gr.Blocks() as settings:
|
|
25 |
gr.Examples(background_examples,background_edit,label="Examples")
|
26 |
clear.click(lambda:None,None,background_edit,queue=False)
|
27 |
submit.click(update_sys,background_edit,background,queue=False)
|
28 |
-
with gr.Row():
|
29 |
-
|
30 |
|
31 |
-
voices_list.change(lambda voice:App_state.update({"voice":voice}),voices_list,queue=False)
|
32 |
|
33 |
with gr.Blocks() as chat_window:
|
34 |
with gr.Row():
|
@@ -37,15 +37,15 @@ with gr.Blocks() as chat_window:
|
|
37 |
chatbot_speech = gr.Audio()
|
38 |
with gr.Column():
|
39 |
chat_clear = gr.Button("Clear")
|
40 |
-
play_speech = gr.Button("Play")
|
41 |
chat_clear.click(lambda:None,None,chatbot,queue=False)
|
42 |
-
play_speech.click(text_to_audio,chatbot,chatbot_speech,queue=False)
|
43 |
|
44 |
with gr.Column():
|
45 |
msg = gr.Textbox()
|
46 |
submit = gr.Button("Submit")
|
47 |
gr.Examples(["Hello","How are you?"],msg,label="Examples")
|
48 |
-
audio = gr.Audio(
|
49 |
# gr.Interface(translate,inputs=gr.Audio(source="microphone",type="filepath"),outputs = "text")
|
50 |
|
51 |
audio.change(translate,audio,msg,queue=False)
|
|
|
25 |
gr.Examples(background_examples,background_edit,label="Examples")
|
26 |
clear.click(lambda:None,None,background_edit,queue=False)
|
27 |
submit.click(update_sys,background_edit,background,queue=False)
|
28 |
+
# with gr.Row():
|
29 |
+
# voices_list = gr.Dropdown([v["Name"] for v in get_voices()],label="Voices")
|
30 |
|
31 |
+
# voices_list.change(lambda voice:App_state.update({"voice":voice}),voices_list,queue=False)
|
32 |
|
33 |
with gr.Blocks() as chat_window:
|
34 |
with gr.Row():
|
|
|
37 |
chatbot_speech = gr.Audio()
|
38 |
with gr.Column():
|
39 |
chat_clear = gr.Button("Clear")
|
40 |
+
# play_speech = gr.Button("Play")
|
41 |
chat_clear.click(lambda:None,None,chatbot,queue=False)
|
42 |
+
# play_speech.click(text_to_audio,chatbot,chatbot_speech,queue=False)
|
43 |
|
44 |
with gr.Column():
|
45 |
msg = gr.Textbox()
|
46 |
submit = gr.Button("Submit")
|
47 |
gr.Examples(["Hello","How are you?"],msg,label="Examples")
|
48 |
+
audio = gr.Audio(sources="microphone",type="filepath")
|
49 |
# gr.Interface(translate,inputs=gr.Audio(source="microphone",type="filepath"),outputs = "text")
|
50 |
|
51 |
audio.change(translate,audio,msg,queue=False)
|
supplier.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import openai
|
2 |
-
import boto3
|
3 |
import os
|
4 |
|
5 |
import pydub
|
@@ -7,8 +7,8 @@ import numpy as np
|
|
7 |
|
8 |
# setup the api keys
|
9 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
10 |
-
aws_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID")
|
11 |
-
aws_secret_access_key = os.environ.get("AWS_SECRET_ACCESS_KEY")
|
12 |
|
13 |
sys_msg = [{
|
14 |
"role": "system",
|
@@ -27,28 +27,28 @@ App_state = {
|
|
27 |
}
|
28 |
|
29 |
# setup the polly client
|
30 |
-
polly_client = boto3.client(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
def get_voices():
|
37 |
-
|
38 |
-
|
39 |
-
# return the audio based on the text
|
40 |
-
def text_to_audio(messages,voice="Joanna",sample_rate = 22050):
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
|
50 |
|
51 |
-
|
52 |
|
53 |
def send_chat(text,messages=[]):
|
54 |
'''
|
@@ -81,12 +81,12 @@ def send_chat(text,messages=[]):
|
|
81 |
}
|
82 |
])
|
83 |
|
84 |
-
res = openai.
|
85 |
-
model="gpt-
|
86 |
messages=openai_messages
|
87 |
)
|
88 |
|
89 |
-
assistant_text = res.choices[0]
|
90 |
|
91 |
messages.append((text,assistant_text))
|
92 |
App_state.update({"messages":messages})
|
@@ -96,7 +96,9 @@ def send_chat(text,messages=[]):
|
|
96 |
def translate(file_path):
|
97 |
if file_path:
|
98 |
f = open(file_path,"rb")
|
99 |
-
res = openai.
|
100 |
-
|
|
|
|
|
101 |
else:
|
102 |
return ""
|
|
|
1 |
import openai
|
2 |
+
# import boto3
|
3 |
import os
|
4 |
|
5 |
import pydub
|
|
|
7 |
|
8 |
# setup the api keys
|
9 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
10 |
+
# aws_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID")
|
11 |
+
# aws_secret_access_key = os.environ.get("AWS_SECRET_ACCESS_KEY")
|
12 |
|
13 |
sys_msg = [{
|
14 |
"role": "system",
|
|
|
27 |
}
|
28 |
|
29 |
# setup the polly client
|
30 |
+
# polly_client = boto3.client(
|
31 |
+
# "polly", # the service we want to use
|
32 |
+
# aws_access_key_id=aws_access_key_id,
|
33 |
+
# aws_secret_access_key=aws_secret_access_key,
|
34 |
+
# region_name='us-east-1')
|
35 |
+
|
36 |
+
# def get_voices():
|
37 |
+
# return polly_client.describe_voices()["Voices"]
|
38 |
+
|
39 |
+
# # return the audio based on the text
|
40 |
+
# def text_to_audio(messages,voice="Joanna",sample_rate = 22050):
|
41 |
+
# text = messages[-1][1]
|
42 |
+
# response = polly_client.synthesize_speech(VoiceId=voice,
|
43 |
+
# OutputFormat='mp3',
|
44 |
+
# SampleRate=str(sample_rate),
|
45 |
+
# Text = text)
|
46 |
|
47 |
+
# buffer = response["AudioStream"].read()
|
48 |
+
# audio_stream = np.frombuffer(buffer,dtype=np.uint16)
|
49 |
|
50 |
|
51 |
+
# return sample_rate,audio_stream
|
52 |
|
53 |
def send_chat(text,messages=[]):
|
54 |
'''
|
|
|
81 |
}
|
82 |
])
|
83 |
|
84 |
+
res = openai.chat.completions.create(
|
85 |
+
model="gpt-4-turbo",
|
86 |
messages=openai_messages
|
87 |
)
|
88 |
|
89 |
+
assistant_text = res.choices[0].message.content
|
90 |
|
91 |
messages.append((text,assistant_text))
|
92 |
App_state.update({"messages":messages})
|
|
|
96 |
def translate(file_path):
|
97 |
if file_path:
|
98 |
f = open(file_path,"rb")
|
99 |
+
res = openai.audio.translations.create(
|
100 |
+
file=f,
|
101 |
+
model="whisper-1")
|
102 |
+
return res.text
|
103 |
else:
|
104 |
return ""
|