Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,8 +14,7 @@ from reportlab.lib.enums import TA_CENTER
|
|
| 14 |
openai.api_key = os.environ['chat_key']
|
| 15 |
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
# 生成聊天回复
|
| 20 |
response = openai.ChatCompletion.create(
|
| 21 |
model= model,
|
|
@@ -34,9 +33,32 @@ def chat_gpt(user_message, model="gpt-3.5-turbo", max_tokens=4096):
|
|
| 34 |
# 将助手回复添加到对应的会话中
|
| 35 |
return assistant_response
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
| 14 |
openai.api_key = os.environ['chat_key']
|
| 15 |
|
| 16 |
|
| 17 |
+
def trans_cn_en(user_message, model="gpt-3.5-turbo", max_tokens=4096):
|
|
|
|
| 18 |
# 生成聊天回复
|
| 19 |
response = openai.ChatCompletion.create(
|
| 20 |
model= model,
|
|
|
|
| 33 |
# 将助手回复添加到对应的会话中
|
| 34 |
return assistant_response
|
| 35 |
|
| 36 |
+
input_cn = gr.inputs.Textbox(lines=5, placeholder="请输入你的中文提示语")
|
| 37 |
+
output_cn = gr.outputs.Textbox()
|
| 38 |
+
iface_cn = gr.Interface(fn=trans_cn_en, inputs=input_cn, outputs=output_en, title="提示词", description="sd提示词中文转英文")
|
| 39 |
+
|
| 40 |
+
def trans_en(user_message, model="gpt-3.5-turbo", max_tokens=4096):
|
| 41 |
+
# 生成聊天回复
|
| 42 |
+
response = openai.ChatCompletion.create(
|
| 43 |
+
model= model,
|
| 44 |
+
messages=[{"role": "system", "content": "translate my input into prompts using for stable diffusion in Chinese language"}] +
|
| 45 |
+
[{"role": "user", "content": user_message}],
|
| 46 |
+
# system 中 定义回答问题的具体类型等
|
| 47 |
+
temperature=0.5,
|
| 48 |
+
max_tokens=150,
|
| 49 |
+
top_p=1,
|
| 50 |
+
frequency_penalty=0,
|
| 51 |
+
presence_penalty=0,
|
| 52 |
+
stop=["\n\n"],
|
| 53 |
+
)
|
| 54 |
+
assistant_response = response.choices[0].message.content
|
| 55 |
+
|
| 56 |
+
# 将助手回复添加到对应的会话中
|
| 57 |
+
return assistant_response
|
| 58 |
|
| 59 |
+
input_en = gr.inputs.Textbox(lines=5, placeholder="请输入你的英文提示语")
|
| 60 |
+
output_en = gr.outputs.Textbox()
|
| 61 |
+
iface_en = gr.Interface(fn=trans_en, inputs=input_en, outputs=output_en, title="提示词", description="sd提示词英文转中文")
|
| 62 |
|
| 63 |
+
iface_cn.launch()
|
| 64 |
+
iface_en.launch()
|