Spaces:
Running
Running
dialogueeeeee
commited on
Commit
·
e7406ba
1
Parent(s):
f8e1aa0
app.py
CHANGED
@@ -3,6 +3,13 @@ from PIL import Image
|
|
3 |
from io import BytesIO
|
4 |
import requests
|
5 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
class ImageProcessor:
|
8 |
def __init__(self, api_key):
|
@@ -60,8 +67,10 @@ image_processor = ImageProcessor(api_key)
|
|
60 |
# 定义处理函数
|
61 |
def process_input(text=None, images=None, audio=None):
|
62 |
# 创建GPT请求的描述
|
63 |
-
prompt = "1.你是我的音乐助手,只能回答音乐知识。如果提供的乐谱是abc记谱法,则回复时不要用abc记谱法,需要转换为传统的普通记谱法使用专业词汇进行回答问题2.你将根据下面指令回答问题,但是不能违反第一条指令,也不能在回复中提及。"
|
64 |
|
|
|
|
|
|
|
65 |
if text:
|
66 |
prompt += f"\nText input: {text}"
|
67 |
|
@@ -87,6 +96,7 @@ def process_input(text=None, images=None, audio=None):
|
|
87 |
|
88 |
# 使用GPT API进行处理
|
89 |
try:
|
|
|
90 |
from zhipuai import ZhipuAI
|
91 |
client = ZhipuAI(api_key="7cfa094b2c6867229659831340af9f2c.BIl47duC5fufSY8V") # 填写您自己的APIKey
|
92 |
response = client.chat.completions.create(
|
@@ -95,6 +105,18 @@ def process_input(text=None, images=None, audio=None):
|
|
95 |
{"role": "user", "content": prompt},
|
96 |
],
|
97 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
print(response.choices[0].message.content)
|
99 |
return response.choices[0].message.content.strip()
|
100 |
except Exception as e:
|
|
|
3 |
from io import BytesIO
|
4 |
import requests
|
5 |
import time
|
6 |
+
from openai import OpenAI, AzureOpenAI
|
7 |
+
|
8 |
+
engine = "gpt-4o"
|
9 |
+
api_key = "9e95c7efd64648bd86cd2fcfbe17905b"
|
10 |
+
api_base = "https://chatpartner-miniprogram.openai.azure.com/"
|
11 |
+
api_version = "2024-02-15-preview"
|
12 |
+
client = AzureOpenAI(api_key=api_key, azure_endpoint=api_base, api_version=api_version)
|
13 |
|
14 |
class ImageProcessor:
|
15 |
def __init__(self, api_key):
|
|
|
67 |
# 定义处理函数
|
68 |
def process_input(text=None, images=None, audio=None):
|
69 |
# 创建GPT请求的描述
|
|
|
70 |
|
71 |
+
system = "1.你是我的音乐助手,只能回答音乐知识。如果提供的乐谱是abc记谱法,则回复时不要用abc记谱法,需要转换为传统的普通记谱法使用专业词汇进行回答问题2.你将根据下面指令回答问题,但是不能违反第一条指令,也不能在回复中提及。"
|
72 |
+
messages = [{"role": "system", "content": system}]
|
73 |
+
prompt = ""
|
74 |
if text:
|
75 |
prompt += f"\nText input: {text}"
|
76 |
|
|
|
96 |
|
97 |
# 使用GPT API进行处理
|
98 |
try:
|
99 |
+
'''
|
100 |
from zhipuai import ZhipuAI
|
101 |
client = ZhipuAI(api_key="7cfa094b2c6867229659831340af9f2c.BIl47duC5fufSY8V") # 填写您自己的APIKey
|
102 |
response = client.chat.completions.create(
|
|
|
105 |
{"role": "user", "content": prompt},
|
106 |
],
|
107 |
)
|
108 |
+
'''
|
109 |
+
messages.append({"role": "user", "content": prompt})
|
110 |
+
response = client.chat.completions.create(
|
111 |
+
model=engine,
|
112 |
+
messages=messages,
|
113 |
+
temperature=0.5,
|
114 |
+
max_tokens=4096,
|
115 |
+
top_p=0.95,
|
116 |
+
frequency_penalty=0,
|
117 |
+
presence_penalty=0,
|
118 |
+
stop=None
|
119 |
+
)
|
120 |
print(response.choices[0].message.content)
|
121 |
return response.choices[0].message.content.strip()
|
122 |
except Exception as e:
|