seawolf2357 commited on
Commit
a46b0f6
ยท
verified ยท
1 Parent(s): 5e514b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -1,24 +1,19 @@
1
  import gradio as gr
2
- from transformers import StableDiffusionPipeline
3
- import torch
4
 
5
- # ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
6
- pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5",
7
- use_auth_token=True)
8
- pipe.to("cuda" if torch.cuda.is_available() else "cpu")
9
 
10
- # ํ…์ŠคํŠธ ํ”„๋กฌํ”„ํŠธ๋กœ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
11
- def generate_image(prompt):
12
- with torch.autocast("cuda"):
13
- image = pipe(prompt).images[0]
14
- return image
15
 
16
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
17
  iface = gr.Interface(
18
- fn=generate_image,
19
- inputs=gr.Textbox(label="Enter a prompt for the AI to generate an image"),
20
- outputs=gr.Image(type="pil"),
21
  )
22
 
23
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
24
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # ๋ชจ๋ธ์„ pipeline์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.
5
+ text_gen = pipeline("text-generation", model="stabilityai/sdxl-turbo")
 
 
6
 
7
+ def generate_text(prompt):
8
+ # ์ƒ์„ฑ๋œ ํ…์ŠคํŠธ๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.
9
+ return text_gen(prompt, max_length=50, do_sample=True)[0]['generated_text']
 
 
10
 
11
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
12
  iface = gr.Interface(
13
+ fn=generate_text,
14
+ inputs=gr.Textbox(lines=2, placeholder="Enter a prompt to generate text"),
15
+ outputs=gr.Textbox(),
16
  )
17
 
18
+ # ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
19
  iface.launch()