glt3953 commited on
Commit
5a94d3a
·
1 Parent(s): 4ced2d1
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #安装一下 Python 的 Gradio 的包:conda install -c conda-forge gradio
2
+ import gradio as gr
3
+ import os
4
+ import openai
5
+
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ def paint(prompt):
9
+ try:
10
+ #惊蛰万物苏醒,清明踏青,秋分桂花飘香,大寒赏雪。
11
+ #晴方好,雨亦奇,来几日,见彩霏。花遮著,人掩扉,但自知,春色在。
12
+ #三月春归,草长莺飞。伴着疫情的寒冬远去,一个崭新的春天正在走近。和春天一起回归的,还有林野间的绚烂山桃花海。
13
+ #落花人独立,微雨燕双飞。
14
+ response = openai.Image.create(
15
+ prompt=prompt,
16
+ n=1,
17
+ size="1024x1024"
18
+ )
19
+ except Exception as e:
20
+ print(e)
21
+ return e
22
+
23
+ return response["data"][0]["url"]
24
+
25
+ print("你是一位画家,需要根据用户的描述绘画,并提供相应的下载地址")
26
+
27
+ def answer(question, history=[]):
28
+ history.append(question)
29
+ response = paint(question)
30
+ history.append(response)
31
+ responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
32
+ return responses, history
33
+
34
+ with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as demo:
35
+ chatbot = gr.Chatbot(elem_id="chatbot")
36
+ state = gr.State([])
37
+
38
+ with gr.Row():
39
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
40
+
41
+ txt.submit(answer, [txt, state], [chatbot, state])
42
+
43
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai