|
import gradio as gr |
|
import os |
|
import openai |
|
|
|
|
|
|
|
|
|
openai.api_key = os.getenv("key1") |
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = '你现在需要帮我做提示词翻译,将我的要求翻译成英语词汇,并且直接添加上适当的其他词语,用来作为绘画AI的提示词。例如,我的要求是:画一只赛博朋克的兔子的时候,你需要第一步翻译我的要求:a rabbit, cyberpunk style, 然后直接添加更多提示词,给你一个示范,a rabbit, cyberpunk style, character design, color page, 4 k, tone mapping, doll, 每个英文单词之间用英文的逗号隔开,不换号。直提提供可以复制黏贴到绘画AI里的提示词,不做解释和互动。如果你了解我的要求,那我们就开始。现在我的要求是' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chat(p, qid, uid): |
|
return ["text", callapi(p)] |
|
|
|
def callapi(p): |
|
response = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo", |
|
messages= [{"role":"system", "content":prompt}, |
|
{"role":"user", "content":p} |
|
] |
|
) |
|
print(response) |
|
response = response["choices"][0]["message"]["content"] |
|
while response.startswith("\n"): |
|
response = response[1:] |
|
return response |
|
|
|
|
|
|
|
iface = gr.Interface(fn=chat, |
|
inputs=["text", "text", "text"], |
|
outputs=["text", "text"], |
|
description=""" |
|
我是绘画助理,可以帮你把想画的内容补充完善并翻译成英语提示词,这样你就可以用更详细的描述让AI帮你画出精美的图~ |
|
比如,你可以输入:一只赛博朋克的兔子 |
|
然后复制提示词去[这里画画!](https://huggingface.co/spaces/Dao3/Top-20-Models) |
|
""") |
|
|
|
iface.launch() |