File size: 577 Bytes
cf8bafe
65ad1db
 
cf8bafe
65ad1db
 
cf8bafe
65ad1db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline

model_id = "CompVis/stable-diffusion-v1-4"
device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = StableDiffusionPipeline.from_pretrained(
    model_id, torch_dtype=torch.float32)

pipe = pipe.to(device)

def generatorImage(name):
    prompt = name
    image = pipe(prompt).images[0]
    image_name = '-'.join(prompt.split()) + ".png"
    image.save("./images/" + image_name)

    return image_name



iface = gr.Interface(fn=generatorImage, inputs="text", outputs="text")
iface.launch()