Spaces:
Running
on
Zero
Running
on
Zero
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import AutoPipelineForText2Image
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
import spaces
|
5 |
+
|
6 |
+
if torch.cuda.is_available():
|
7 |
+
device = "cuda"
|
8 |
+
print("Using GPU")
|
9 |
+
else:
|
10 |
+
device = "cpu"
|
11 |
+
print("Using CPU")
|
12 |
+
|
13 |
+
# Initialize the pipeline and download the model
|
14 |
+
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium", torch_dtype=torch.float16)
|
15 |
+
pipe.to(device)
|
16 |
+
|
17 |
+
# Define the image generation function
|
18 |
+
@spaces.GPU(duration=60)
|
19 |
+
def generate_image(prompt):
|
20 |
+
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
21 |
+
return image
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=generate_image,
|
26 |
+
inputs=gr.Textbox(placeholder="Insert Prompt Here..."),
|
27 |
+
outputs="image",
|
28 |
+
title="Stable Diffusion 3 Medium",
|
29 |
+
description="Made by [Nick088](https://linktr.ee/Nick088"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
interface.launch(share=False)
|