closet / app.py
karyappa's picture
Update app.py
205ea1b verified
raw
history blame contribute delete
907 Bytes
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
# Load the model from Hugging Face
model_id = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionPipeline.from_pretrained(model_id)
# Move model to CPU to use free tier
pipe.to("cpu")
# Define function to generate image from text prompt
def generate_image(prompt):
image = pipe(prompt).images[0]
return image
# Create Gradio interface
with gr.Blocks() as demo:
gr.Markdown("## Simple Text-to-Image Generator using Stable Diffusion")
prompt = gr.Textbox(label="Enter a text prompt")
image_output = gr.Image()
# Create a button to trigger image generation
generate_button = gr.Button("Generate Image")
# On clicking the button, call the generate_image function
generate_button.click(fn=generate_image, inputs=prompt, outputs=image_output)
# Launch the demo
demo.launch()