Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the Stable Diffusion model from Hugging Face's diffusers library
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4-original", torch_dtype=torch.float16)
|
7 |
+
pipe.to("cuda")
|
8 |
+
|
9 |
+
def generate_image(prompt):
|
10 |
+
# Generate the image based on the text prompt
|
11 |
+
image = pipe(prompt).images[0]
|
12 |
+
return image
|
13 |
+
|
14 |
+
# Create Gradio interface
|
15 |
+
interface = gr.Interface(fn=generate_image,
|
16 |
+
inputs="text",
|
17 |
+
outputs="image",
|
18 |
+
title="Text to Image Generator",
|
19 |
+
description="Generate images from text using Stable Diffusion.")
|
20 |
+
|
21 |
+
interface.launch()
|