Spaces:
Sleeping
Sleeping
Commit
·
ee55365
1
Parent(s):
bfbfc93
sending app.py
Browse files- app.py +22 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Initialize the model pipeline
|
6 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0",
|
7 |
+
torch_dtype=torch.float16,
|
8 |
+
use_safetensors=True,
|
9 |
+
variant="fp16")
|
10 |
+
|
11 |
+
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
+
|
13 |
+
# Define the inference function
|
14 |
+
def generate_image(prompt):
|
15 |
+
image = pipe(prompt).images[0]
|
16 |
+
return image
|
17 |
+
|
18 |
+
# Create the Gradio interface
|
19 |
+
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", live=True)
|
20 |
+
|
21 |
+
# Launch the Gradio app
|
22 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
diffusers
|
2 |
+
torch
|
3 |
+
gradio
|