File size: 745 Bytes
472a47d
 
 
9c4e88f
472a47d
d2191a8
9c4e88f
22177c2
472a47d
8eabfed
6ef0474
472a47d
 
 
d2191a8
6ef0474
472a47d
d2191a8
472a47d
 
 
 
 
 
 
 
 
 
 
d2191a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)

@GPU  # πŸ‘ˆ 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()