Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the SDXL-Turbo model
|
6 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
7 |
+
pipe.to("cuda")
|
8 |
+
|
9 |
+
# Define the image generation function
|
10 |
+
def generate_image(prompt, steps, guidance):
|
11 |
+
image = pipe(prompt=prompt, num_inference_steps=steps, guidance_scale=guidance).images[0]
|
12 |
+
return image
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=generate_image,
|
17 |
+
inputs=[
|
18 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt"),
|
19 |
+
gr.inputs.Slider(minimum=1, maximum=50, default=10, step=1, label="Inference Steps"),
|
20 |
+
gr.inputs.Slider(minimum=0.0, maximum=20.0, default=8.0, step=0.5, label="Guidance Scale")
|
21 |
+
],
|
22 |
+
outputs=gr.outputs.Image(type="pil", label="Generated Image"),
|
23 |
+
title="SDXL-Turbo Image Generator",
|
24 |
+
description="Generate images based on text prompts using the SDXL-Turbo model."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Launch the interface
|
28 |
+
iface.launch()
|