Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gr as gradio
|
| 2 |
+
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, Prompt
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
system_prompt = [
|
| 6 |
+
{
|
| 7 |
+
"role" : "system",
|
| 8 |
+
"content" : "你是一个非常厉害的音乐制作人,毕业于伯克利音乐学院,专业是音乐制作,你在和弦编配上有独特的见解,擅长用局部离调的方式营造歌曲给人的新鲜感"
|
| 9 |
+
|
| 10 |
+
}
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
|
| 15 |
+
def respond(message, chat_history):
|
| 16 |
+
re_messages = system_prompt
|
| 17 |
+
for chat in chat_history:
|
| 18 |
+
re_messages.append({"role": "user", "content": chat[0]})
|
| 19 |
+
re_messages.append({"role": "assistant", "content": chat[1]})
|
| 20 |
+
re_messages.append({"role": "user", "content": message})
|
| 21 |
+
re_chat_completion = openai.ChatCompletion.create(
|
| 22 |
+
model='gpt-3.5-turbo',
|
| 23 |
+
messages=re_messages,
|
| 24 |
+
temperature=0.7
|
| 25 |
+
)
|
| 26 |
+
bot_message = re_chat_completion.choices[0].message.content
|
| 27 |
+
chat_history.append((message, bot_message))
|
| 28 |
+
return "", chat_history
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
chatbot = gr.Chatbot(label='历史会话')
|
| 33 |
+
msg = gr.Textbox(label='回车输入')
|
| 34 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 35 |
+
|
| 36 |
+
demo.launch(share=True)
|