Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,13 +5,14 @@ import requests
|
|
5 |
from pydub import AudioSegment as am
|
6 |
from xml.etree import ElementTree
|
7 |
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
openai.api_type = "azure"
|
12 |
-
openai.api_base =
|
13 |
openai.api_version = "2023-03-15-preview"
|
14 |
-
openai.api_key =
|
15 |
|
16 |
messages_gpt = []
|
17 |
messages_chat = [
|
@@ -23,9 +24,21 @@ messages_vchat = [
|
|
23 |
{"role": "system", "content": "You are an AI assistant that helps people find information and just response with SSML."},
|
24 |
]
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
with gr.Blocks() as page:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
with gr.Tabs():
|
28 |
-
with gr.TabItem("GPT
|
29 |
ui_chatbot_gpt = gr.Chatbot(label="GPT Playground:")
|
30 |
with gr.Row():
|
31 |
with gr.Column(scale=0.9):
|
@@ -102,7 +115,7 @@ with gr.Blocks() as page:
|
|
102 |
ui_prompt_sys = gr.Textbox(value="You are an AI assistant that helps people find information.", show_label=False, interactive=True).style(container=False)
|
103 |
with gr.Row():
|
104 |
ui_temp_chat = gr.Slider(0.1, 1.0, 0.7, step=0.1, label="Temperature", interactive=True)
|
105 |
-
ui_max_tokens_chat = gr.Slider(100, 8000,
|
106 |
ui_top_p_chat = gr.Slider(0.05, 1.0, 0.9, step=0.1, label="Top P", interactive=True)
|
107 |
with gr.Accordion("Select radio button to see detail:", open=False):
|
108 |
ui_res_radio_chat = gr.Radio(["Response from OpenAI Model", "Prompt messages history"], label="Show OpenAI response:", interactive=True)
|
@@ -163,7 +176,7 @@ with gr.Blocks() as page:
|
|
163 |
ui_clear_chat.click(lambda: None, None, ui_chatbot_chat, queue=False).then(reset_sys, ui_prompt_sys)
|
164 |
|
165 |
|
166 |
-
with gr.TabItem("
|
167 |
ui_prompt_walle = gr.Textbox(placeholder="Please enter your prompt here to generate image.", show_label=False).style(container=False)
|
168 |
ui_image_walle = gr.Image()
|
169 |
with gr.Accordion("Select radio button to see detail:", open=False):
|
@@ -172,8 +185,8 @@ with gr.Blocks() as page:
|
|
172 |
def get_image_walle(prompt_walle):
|
173 |
global response_walle
|
174 |
walle_api_version = '2022-08-03-preview'
|
175 |
-
url = "{}dalle/text-to-image?api-version={}".format(api_base, walle_api_version)
|
176 |
-
headers= { "api-key": api_key, "Content-Type": "application/json" }
|
177 |
body = {
|
178 |
"caption": prompt_walle,
|
179 |
"resolution": "1024x1024"
|
@@ -204,6 +217,11 @@ with gr.Blocks() as page:
|
|
204 |
with gr.Column():
|
205 |
with gr.Accordion("Expand to config parameters:", open=False):
|
206 |
ui_prompt_sys_vchat = gr.Textbox(value="You are an AI assistant that helps people find information and just response with SSML.", show_label=False, interactive=True).style(container=False)
|
|
|
|
|
|
|
|
|
|
|
207 |
ui_voice_inc_vchat = gr.Audio(source="microphone", type="filepath")
|
208 |
ui_voice_out_vchat = gr.Audio(value=None, type="filepath", interactive=False).style(container=False)
|
209 |
with gr.Accordion("Expand to config parameters:", open=False):
|
@@ -238,7 +256,7 @@ with gr.Blocks() as page:
|
|
238 |
voice_wav = voice_wav.set_frame_rate(16000)
|
239 |
voice_wav.export(voice_message, format='wav')
|
240 |
# STT
|
241 |
-
|
242 |
service_region = "westus"
|
243 |
|
244 |
base_url = "https://"+service_region+".stt.speech.microsoft.com/"
|
@@ -267,7 +285,7 @@ with gr.Blocks() as page:
|
|
267 |
return sst_text
|
268 |
|
269 |
def text_to_speech():
|
270 |
-
OASK_Speech =
|
271 |
service_region = "westus"
|
272 |
|
273 |
base_url = "https://"+service_region+".tts.speech.microsoft.com/"
|
@@ -329,7 +347,4 @@ with gr.Blocks() as page:
|
|
329 |
bot_vchat, ui_chatbot_vchat, ui_chatbot_vchat, queue=False).then(text_to_speech, None, ui_voice_out_vchat)
|
330 |
|
331 |
|
332 |
-
page.launch(share=False)
|
333 |
-
|
334 |
-
|
335 |
-
|
|
|
5 |
from pydub import AudioSegment as am
|
6 |
from xml.etree import ElementTree
|
7 |
|
8 |
+
aoai_url = "https://mvp-azureopenai.openai.azure.com/"
|
9 |
+
aoai_key = ""
|
10 |
+
stts_key = ""
|
11 |
|
12 |
openai.api_type = "azure"
|
13 |
+
openai.api_base = "https://mvp-azureopenai.openai.azure.com/"
|
14 |
openai.api_version = "2023-03-15-preview"
|
15 |
+
# openai.api_key = aoai_key
|
16 |
|
17 |
messages_gpt = []
|
18 |
messages_chat = [
|
|
|
24 |
{"role": "system", "content": "You are an AI assistant that helps people find information and just response with SSML."},
|
25 |
]
|
26 |
|
27 |
+
def get_aoai_key(txt_inpout):
|
28 |
+
if txt_inpout:
|
29 |
+
openai.api_key = txt_inpout
|
30 |
+
return gr.update(value=txt_inpout)
|
31 |
+
|
32 |
with gr.Blocks() as page:
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column(scale=0.4):
|
35 |
+
gr.Markdown("Your Key will not be saved or viewed by anyone.")
|
36 |
+
with gr.Column(scale=0.6):
|
37 |
+
ui_aoai_key = gr.Textbox(placeholder="Please enter your Azure OpenAI API key here.", lines=1, show_label=False, type='password').style(container=False)
|
38 |
+
ui_aoai_key.submit(get_aoai_key, ui_aoai_key, ui_aoai_key)
|
39 |
+
|
40 |
with gr.Tabs():
|
41 |
+
with gr.TabItem("GPT Playground"):
|
42 |
ui_chatbot_gpt = gr.Chatbot(label="GPT Playground:")
|
43 |
with gr.Row():
|
44 |
with gr.Column(scale=0.9):
|
|
|
115 |
ui_prompt_sys = gr.Textbox(value="You are an AI assistant that helps people find information.", show_label=False, interactive=True).style(container=False)
|
116 |
with gr.Row():
|
117 |
ui_temp_chat = gr.Slider(0.1, 1.0, 0.7, step=0.1, label="Temperature", interactive=True)
|
118 |
+
ui_max_tokens_chat = gr.Slider(100, 8000, 2000, step=100, label="Max Tokens", interactive=True)
|
119 |
ui_top_p_chat = gr.Slider(0.05, 1.0, 0.9, step=0.1, label="Top P", interactive=True)
|
120 |
with gr.Accordion("Select radio button to see detail:", open=False):
|
121 |
ui_res_radio_chat = gr.Radio(["Response from OpenAI Model", "Prompt messages history"], label="Show OpenAI response:", interactive=True)
|
|
|
176 |
ui_clear_chat.click(lambda: None, None, ui_chatbot_chat, queue=False).then(reset_sys, ui_prompt_sys)
|
177 |
|
178 |
|
179 |
+
with gr.TabItem("DALL路E 2"):
|
180 |
ui_prompt_walle = gr.Textbox(placeholder="Please enter your prompt here to generate image.", show_label=False).style(container=False)
|
181 |
ui_image_walle = gr.Image()
|
182 |
with gr.Accordion("Select radio button to see detail:", open=False):
|
|
|
185 |
def get_image_walle(prompt_walle):
|
186 |
global response_walle
|
187 |
walle_api_version = '2022-08-03-preview'
|
188 |
+
url = "{}dalle/text-to-image?api-version={}".format(openai.api_base, walle_api_version)
|
189 |
+
headers= { "api-key": openai.api_key, "Content-Type": "application/json" }
|
190 |
body = {
|
191 |
"caption": prompt_walle,
|
192 |
"resolution": "1024x1024"
|
|
|
217 |
with gr.Column():
|
218 |
with gr.Accordion("Expand to config parameters:", open=False):
|
219 |
ui_prompt_sys_vchat = gr.Textbox(value="You are an AI assistant that helps people find information and just response with SSML.", show_label=False, interactive=True).style(container=False)
|
220 |
+
ui_stts_key = gr.Textbox(placeholder="Input your Azure Speech service API key", show_label=False, interactive=True).style(container=False)
|
221 |
+
ui_stts_key.submit(lambda x: None, ui_stts_key)
|
222 |
+
stts_key = ui_aoai_key.value
|
223 |
+
print(stts_key)
|
224 |
+
|
225 |
ui_voice_inc_vchat = gr.Audio(source="microphone", type="filepath")
|
226 |
ui_voice_out_vchat = gr.Audio(value=None, type="filepath", interactive=False).style(container=False)
|
227 |
with gr.Accordion("Expand to config parameters:", open=False):
|
|
|
256 |
voice_wav = voice_wav.set_frame_rate(16000)
|
257 |
voice_wav.export(voice_message, format='wav')
|
258 |
# STT
|
259 |
+
OASK = stts_key
|
260 |
service_region = "westus"
|
261 |
|
262 |
base_url = "https://"+service_region+".stt.speech.microsoft.com/"
|
|
|
285 |
return sst_text
|
286 |
|
287 |
def text_to_speech():
|
288 |
+
OASK_Speech = stts_key
|
289 |
service_region = "westus"
|
290 |
|
291 |
base_url = "https://"+service_region+".tts.speech.microsoft.com/"
|
|
|
347 |
bot_vchat, ui_chatbot_vchat, ui_chatbot_vchat, queue=False).then(text_to_speech, None, ui_voice_out_vchat)
|
348 |
|
349 |
|
350 |
+
page.launch(share=False)
|
|
|
|
|
|