imagegen / app.py
aramkris's picture
Update app.py
92764fc
Raw History Blame Contribute Delete
1.67 kB
import os
import gradio as gr
import torch
#from diffusers import DiffusionPipeline
from diffusers import StableDiffusionPipeline
print(f"Is CUDA available: {torch.cuda.is_available()}")
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, revision="fp16")
pipe = pipe.to("cuda")
prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]
model_id = "runwayml/stable-diffusion-v1-5"
#if torch.cuda.is_available():
# print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
# pipe_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=os.getenv("HUGGING_FACE_HUB_TOKEN"))
# pipe_sd = pipe_sd.to("cuda")
#else:
# pipe_sd = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=os.getenv("HUGGING_FACE_HUB_TOKEN"))
examples = [
["A teddy bear playing in the pool."],
["A simple wedding cake with lego bride and groom topper and cake pops."],
["A realistic tree using a mixture of different colored pencils."],
["Diwali greetings with lots of crackers"],
["A man with a pineapple head."],
["Pebble tower standing on the left on the sea beach."],
]
title = "Stable Diffusion 1-5"
description = "A simple demo with Stable-Diffusion-v1-5 for text to image generation."
def inference(text):
output_sd = pipe_sd(text).images[0]
return [output_sd]
io = gr.Interface(
inference,
gr.Textbox(lines=3),
outputs=[
gr.Image(type="pil", label="Stable Diffusion"),
],
title=title,
description=description,
examples=examples
)
io.launch()