Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import StableDiffusionPipeline | |
| import torch | |
| # ๋ชจ๋ธ ์ด๊ธฐํ | |
| pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", | |
| use_auth_token=True) | |
| pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| # ํ ์คํธ ํ๋กฌํํธ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ํจ์ | |
| def generate_image(prompt): | |
| with torch.autocast("cuda"): | |
| image = pipe(prompt).images[0] | |
| return image | |
| # Gradio ์ธํฐํ์ด์ค ์ ์ | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs=gr.Textbox(label="Enter a prompt for the AI to generate an image"), | |
| outputs=gr.Image(type="pil"), | |
| ) | |
| # ์ธํฐํ์ด์ค ์คํ | |
| iface.launch() |