Spaces:
Runtime error
Runtime error
Commit Β·
8b26c2f
1
Parent(s): 7f32f91
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import DiffusionPipeline
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 7 |
+
pipe.to("cuda")
|
| 8 |
+
|
| 9 |
+
def generate_image(prompt):
|
| 10 |
+
result = pipe(prompt=prompt)
|
| 11 |
+
image = result.images[0]
|
| 12 |
+
# Convert the image tensor to a format suitable for Gradio (assuming image is in [C, H, W] format)
|
| 13 |
+
return image.permute(1, 2, 0).cpu().numpy()
|
| 14 |
+
|
| 15 |
+
# Define Gradio interface
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 19 |
+
outputs="image",
|
| 20 |
+
live=True,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
iface.launch(share=True)
|
| 24 |
+
|