trials_class_1 / app.py
dalexandre's picture
Update app.py
0c6b3e2 verified
Raw History Blame Contribute Delete
1.13 kB
import gradio as gr
from diffusers import StableDiffusionPipeline
def generate_image(prompt):
# Load the pre-trained Stable Diffusion model from Hugging Face
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4",
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=True) # You need your Hugging Face token here
pipe = pipe.to("cuda") # Use GPU if available
# Generate the image based on the prompt
image = pipe(prompt).images[0]
# Convert image to display it with Gradio
return image
# Create the Gradio interface
iface = gr.Interface(fn=generate_image,
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
outputs="image",
title="Stable Diffusion Text-to-Image Generator",
description="This app uses Stable Diffusion to generate images based on your text prompts.")
# Run the Gradio app
iface.launch()