Spaces:
Sleeping
Sleeping
File size: 1,076 Bytes
08acb07 c1d63ae d3db117 |
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 32 33 34 35 36 37 38 |
import os
os.system("pip install diffusers torch transformers accelerate gradio")
import gradio as gr
from diffusers import StableDiffusionPipeline
# Load the Stable Diffusion model
model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
def generate_image(prompt):
# Generate an image based on the prompt
image = model(prompt).images[0]
return image
# Create a Gradio interface
interface = gr.Interface(
fn=generate_image,
inputs="text",
outputs="image",
title="AI Image Generator",
description="Enter a prompt to generate an image using Stable Diffusion."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()
model = StableDiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V4.0")
import torch
from diffusers import StableDiffusionPipeline
model = StableDiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V4.0").to("cuda")
model.unet = torch.compile(model.unet) # Speeds up inference
def generate_image(prompt):
image = model(prompt).images[0]
return image
|