Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Stable Diffusion generation function
|
| 6 |
def generate_image(prompt):
|
| 7 |
-
|
| 8 |
-
"stability-ai/stable-diffusion-3-5-large:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
|
| 9 |
-
input={"prompt": prompt}
|
| 10 |
-
)
|
| 11 |
-
return output[0]
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
with gr.
|
| 16 |
-
gr.
|
| 17 |
-
gr.
|
| 18 |
-
|
| 19 |
-
label="Enter Replicate API key",
|
| 20 |
-
type="password",
|
| 21 |
-
placeholder="Paste your Replicate API key here (or set as environment variable)"
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
prompt = gr.Textbox(label="Prompt", placeholder="A cute corgi in a astronaut helmet")
|
| 25 |
-
generate_btn = gr.Button("Generate")
|
| 26 |
-
output = gr.Image(label="Generated Image")
|
| 27 |
|
| 28 |
-
|
| 29 |
-
fn=generate_image,
|
| 30 |
-
inputs=prompt,
|
| 31 |
-
outputs=output
|
| 32 |
-
)
|
| 33 |
|
| 34 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# This will use CPU and download ~5GB model files
|
| 6 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
"CompVis/stable-diffusion-v1-4",
|
| 8 |
+
torch_dtype=torch.float32,
|
| 9 |
+
use_safetensors=True
|
| 10 |
+
)
|
| 11 |
|
|
|
|
| 12 |
def generate_image(prompt):
|
| 13 |
+
return pipe(prompt).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("## 🐢 Local CPU Generator (SD 1.4)")
|
| 17 |
+
with gr.Row():
|
| 18 |
+
prompt = gr.Textbox(label="Prompt")
|
| 19 |
+
btn = gr.Button("Generate (May take 2-5 mins)")
|
| 20 |
+
output = gr.Image(label="Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
btn.click(fn=generate_image, inputs=prompt, outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo.launch()
|