Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionXLPipeline
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Load the Stable Diffusion XL model
|
6 |
+
pipeline = StableDiffusionXLPipeline.from_pretrained(
|
7 |
+
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
8 |
+
).to("cuda")
|
9 |
+
|
10 |
+
def generate_image(prompt, prompt_2):
|
11 |
+
# Generate the image based on the prompts
|
12 |
+
image = pipeline(prompt=prompt, prompt_2=prompt_2).images[0]
|
13 |
+
|
14 |
+
# Convert the PIL image to a format that Gradio can display
|
15 |
+
return image
|
16 |
+
|
17 |
+
# Define the Gradio interface
|
18 |
+
iface = gr.Interface(fn=generate_image,
|
19 |
+
inputs=[gr.Textbox(label="Prompt 1: Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"),
|
20 |
+
gr.Textbox(label="Prompt 2: Van Gogh painting")],
|
21 |
+
outputs="image",
|
22 |
+
title="Stable Diffusion XL Image Generator",
|
23 |
+
description="Generate images with Stable Diffusion XL based on two prompts.")
|
24 |
+
|
25 |
+
# Launch the Gradio app
|
26 |
+
iface.launch()
|