Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Function to generate the image
|
6 |
+
def generate_image(prompt):
|
7 |
+
# Load the pipeline with default settings which should default to a CPU compatible setting if `fp32` is available
|
8 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
9 |
+
"stabilityai/sdxl-turbo",
|
10 |
+
torch_dtype=torch.float32 # Using float32 for CPU compatibility
|
11 |
+
)
|
12 |
+
pipe = pipe.to("cpu") # Ensure the pipeline is using the CPU
|
13 |
+
|
14 |
+
# Generate the image based on the prompt
|
15 |
+
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
16 |
+
return image
|
17 |
+
|
18 |
+
# Define the Gradio interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=generate_image,
|
21 |
+
inputs=gr.Textbox(label="Enter a description for the image"),
|
22 |
+
outputs=gr.Image(type="pil", label="Generated Image"),
|
23 |
+
title="Image Generator",
|
24 |
+
description="This interface generates images based on your descriptions using the Stability AI SDXL-Turbo model."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Prepare to run in Hugging Face Spaces
|
28 |
+
if __name__ == "__main__":
|
29 |
+
interface.launch()
|