Spaces:
Runtime error
Runtime error
Update app.py
#1
by lea97338 - opened
app.py
CHANGED
|
@@ -1,18 +1,19 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
from diffusers import
|
| 4 |
from tqdm import tqdm
|
| 5 |
|
| 6 |
device = "cpu"
|
| 7 |
-
dtype = torch.bfloat16
|
| 8 |
|
| 9 |
-
pipe =
|
| 10 |
-
"
|
| 11 |
torch_dtype=dtype,
|
| 12 |
low_cpu_mem_usage=True,
|
| 13 |
-
token=None
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
| 16 |
def generate_image(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 17 |
with torch.inference_mode():
|
| 18 |
progress(0, desc="Initialisation...")
|
|
@@ -24,14 +25,14 @@ def generate_image(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 24 |
|
| 25 |
image = pipe(
|
| 26 |
prompt=prompt,
|
| 27 |
-
height=
|
| 28 |
-
width=
|
| 29 |
-
guidance_scale=
|
| 30 |
-
num_inference_steps=
|
| 31 |
).images[0]
|
| 32 |
|
| 33 |
progress(1.0, desc="Terminé !")
|
| 34 |
-
image.save("
|
| 35 |
return image
|
| 36 |
|
| 37 |
css = """
|
|
@@ -53,8 +54,8 @@ demo = gr.Interface(
|
|
| 53 |
fn=generate_image,
|
| 54 |
inputs=gr.Textbox(label="Prompt", placeholder="Décris ton image...", lines=2),
|
| 55 |
outputs=gr.Image(label="Image générée"),
|
| 56 |
-
title="
|
| 57 |
-
description="
|
| 58 |
css=css,
|
| 59 |
)
|
| 60 |
|
|
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
from tqdm import tqdm
|
| 5 |
|
| 6 |
device = "cpu"
|
| 7 |
+
dtype = torch.bfloat16 # si souci, mets torch.float32
|
| 8 |
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 10 |
+
"SG161222/Realistic_Vision_V6.0_B1_noVAE",
|
| 11 |
torch_dtype=dtype,
|
| 12 |
low_cpu_mem_usage=True,
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
+
pipe.enable_sequential_cpu_offload()
|
| 16 |
+
|
| 17 |
def generate_image(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 18 |
with torch.inference_mode():
|
| 19 |
progress(0, desc="Initialisation...")
|
|
|
|
| 25 |
|
| 26 |
image = pipe(
|
| 27 |
prompt=prompt,
|
| 28 |
+
height=512,
|
| 29 |
+
width=512,
|
| 30 |
+
guidance_scale=7.0,
|
| 31 |
+
num_inference_steps=25,
|
| 32 |
).images[0]
|
| 33 |
|
| 34 |
progress(1.0, desc="Terminé !")
|
| 35 |
+
image.save("realistic-vision.png")
|
| 36 |
return image
|
| 37 |
|
| 38 |
css = """
|
|
|
|
| 54 |
fn=generate_image,
|
| 55 |
inputs=gr.Textbox(label="Prompt", placeholder="Décris ton image...", lines=2),
|
| 56 |
outputs=gr.Image(label="Image générée"),
|
| 57 |
+
title="Realistic Vision — CPU",
|
| 58 |
+
description="SD 1.5 photoréaliste, très propre, CPU only",
|
| 59 |
css=css,
|
| 60 |
)
|
| 61 |
|