splendid commited on
Commit
97ae692
ยท
1 Parent(s): 5c35081

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -50
app.py CHANGED
@@ -1,50 +0,0 @@
1
- from typing import TextIO
2
- import keras_cv
3
- from translate import Translator
4
- import matplotlib.pyplot as plt
5
- import gradio as gr
6
- import tensorflow as tf
7
-
8
- model = keras_cv.models.StableDiffusion(img_width=512, img_height=512)
9
- translator = Translator(from_lang="ko", to_lang="en")
10
-
11
-
12
- def generate_img(text:str, cnt:int) -> list:
13
- #์ž…๋ ฅ ๋ฐ›์€ ํ…์ŠคํŠธ๋ฅผ cnt๊ฐœ์˜ ์ด๋ฏธ์ง€๋กœ ์ƒ์„ฑํ•˜์—ฌ return
14
-
15
- text = translator.translate(text)
16
- images = model.text_to_image(text, batch_size=cnt)
17
- return images
18
-
19
- def plot_image(images) -> None:
20
- #์ž…๋ ฅ ๋ฐ›์€ ์ด๋ฏธ์ง€๋“ค์„ ์ด๋ฏธ์ง€๋กœ ์ €์žฅ
21
- plt.figure(figsize=(20, 20))
22
-
23
- for i in range(len(images)):
24
- ax = plt.subplot(1, len(images), i + 1)
25
- plt.imshow(images[i])
26
- plt.axis("off")
27
- plt.tight_layout()
28
-
29
-
30
- plt.savefig(f"text.png")
31
-
32
-
33
- def inference(text:str):
34
- image = generate_img(text, 1).squeeze()
35
- return image
36
-
37
- with gr.Blocks(theme=gr.themes.Base()) as demo:
38
-
39
- with gr.Row():
40
- with gr.Column():
41
-
42
- text=gr.Textbox(lines=5,placeholder='Prompt here',label="prompt")
43
- create_btn = gr.Button(value="Create")
44
- with gr.Column():
45
- output=gr.Image(shape=(200,200))
46
- create_btn.click(fn=inference,inputs=text,outputs=output)
47
- examples = gr.Examples(examples=["The rainbow car", "Ride the cloud into the night sky"],inputs=[text])
48
-
49
-
50
- demo.launch(share=False)