seawolf2357 commited on
Commit
b4f27ac
ยท
verified ยท
1 Parent(s): bf2b986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -1,19 +1,24 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Hugging Face์˜ ํŠธ๋žœ์Šคํฌ๋จธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๋ชจ๋ธ์„ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
5
- model = pipeline("text-classification", model="InstantX/InstantID")
 
 
6
 
7
- # ๋ชจ๋ธ์„ ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
8
- def predict(text):
9
- return model(text)
 
 
10
 
11
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
12
  iface = gr.Interface(
13
- fn=predict,
14
- inputs=gr.Textbox(lines=2, placeholder="Type something here..."),
15
- outputs=[gr.Label(num_top_classes=3), gr.Dataframe()],
16
  )
17
 
18
- # ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
19
  iface.launch()
 
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()