Spaces:
Runtime error
Runtime error
| from diffusers import StableDiffusionPipeline | |
| import gradio as gr | |
| import torch | |
| import os | |
| from huggingface_hub import login | |
| from spaces import GPU # π only for HF Spaces | |
| login(token=os.getenv("HF_TOKEN")) | |
| model_id = "Lookingsoft-team/Text_to_Image_Diffusion" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float16 | |
| ).to(device) | |
| # π this tells HF Space to start with GPU | |
| def generate_image(prompt): | |
| image = pipe(prompt).images[0] | |
| return image | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs=gr.Textbox(label="Enter prompt"), | |
| outputs=gr.Image(type="pil"), | |
| title="Private Stable Diffusion Demo" | |
| ) | |
| iface.launch() | |