AIPaint / app.py
glt3953's picture
Add File
5a94d3a
#安装一下 Python 的 Gradio 的包:conda install -c conda-forge gradio
import gradio as gr
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
def paint(prompt):
try:
#惊蛰万物苏醒,清明踏青,秋分桂花飘香,大寒赏雪。
#晴方好,雨亦奇,来几日,见彩霏。花遮著,人掩扉,但自知,春色在。
#三月春归,草长莺飞。伴着疫情的寒冬远去,一个崭新的春天正在走近。和春天一起回归的,还有林野间的绚烂山桃花海。
#落花人独立,微雨燕双飞。
response = openai.Image.create(
prompt=prompt,
n=1,
size="1024x1024"
)
except Exception as e:
print(e)
return e
return response["data"][0]["url"]
print("你是一位画家,需要根据用户的描述绘画,并提供相应的下载地址")
def answer(question, history=[]):
history.append(question)
response = paint(question)
history.append(response)
responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
return responses, history
with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as demo:
chatbot = gr.Chatbot(elem_id="chatbot")
state = gr.State([])
with gr.Row():
txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
txt.submit(answer, [txt, state], [chatbot, state])
demo.launch()