Spaces:
Runtime error
Runtime error
Commit
·
8735907
1
Parent(s):
4a1cee4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import AutoPipelineForText2Image
|
4 |
+
|
5 |
+
# Install required libraries
|
6 |
+
!pip install diffusers transformers accelerate --upgrade
|
7 |
+
|
8 |
+
# Load pre-trained model and move it to GPU
|
9 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
10 |
+
pipe.to("cuda")
|
11 |
+
|
12 |
+
# Define function to generate image based on input prompt
|
13 |
+
def generate_image(prompt):
|
14 |
+
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
15 |
+
return image
|
16 |
+
|
17 |
+
# Create Gradio interface
|
18 |
+
input_text = gr.inputs.Textbox(lines=5, label="Enter the prompt")
|
19 |
+
output_image = gr.outputs.Image(label="Generated Image")
|
20 |
+
|
21 |
+
# Define Gradio app
|
22 |
+
gr.Interface(
|
23 |
+
generate_image,
|
24 |
+
inputs=input_text,
|
25 |
+
outputs=output_image,
|
26 |
+
title="Stable Diffusion SDXL Turbo",
|
27 |
+
description="Enter a prompt and generate an image based on the input prompt"
|
28 |
+
).launch()
|