Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
-
def to_black(image):
|
5 |
-
output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
6 |
-
return output
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from dalle2 import Dalle2
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
+
def draw(description):
|
8 |
+
print("description"+description)
|
9 |
+
dalle = Dalle2("sess-mDEO1h4fEgZQ4Aksl1qJwNJ1t0e2qEeyrMP4PKnZ")
|
10 |
+
generations = dalle.generate(description)
|
11 |
+
img_list = []
|
12 |
+
for generation in generations:
|
13 |
+
image_url = generation["generation"]["image_path"]
|
14 |
+
# response = requests.get(image_url)
|
15 |
+
# img = Image.open(BytesIO(response.content))
|
16 |
+
im = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
|
17 |
+
img_list.append(im)
|
18 |
+
return img_list
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
with gr.Column(variant="panel"):
|
22 |
+
gr.Markdown("# <center> 🚀你说我画")
|
23 |
+
with gr.Row(variant="compact"):
|
24 |
+
text = gr.Textbox(
|
25 |
+
label="Enter your prompt",
|
26 |
+
show_label=False,
|
27 |
+
max_lines=1,
|
28 |
+
placeholder="请描述你想要的画",
|
29 |
+
).style(
|
30 |
+
container=False,
|
31 |
+
)
|
32 |
+
btn = gr.Button("开始生成").style(full_width=False)
|
33 |
+
|
34 |
+
gallery = gr.Gallery(
|
35 |
+
label="结果", show_label=False, elem_id="gallery"
|
36 |
+
).style(grid=[2], height="auto")
|
37 |
+
|
38 |
+
gr.Markdown("### 叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪叶伟豪")
|
39 |
+
|
40 |
+
btn.click(draw, text, gallery)
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|