src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -3
src/streamlit_app.py
CHANGED
|
@@ -1,9 +1,19 @@
|
|
| 1 |
-
#
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
from diffusers import PaintByExamplePipeline
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
st.set_page_config(page_title="Paint-By-Example", layout="centered")
|
| 8 |
|
| 9 |
@st.cache_resource(show_spinner=False)
|
|
@@ -11,7 +21,8 @@ def load_pipe():
|
|
| 11 |
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 12 |
pipe = PaintByExamplePipeline.from_pretrained(
|
| 13 |
"Fantasy-Studio/Paint-by-Example",
|
| 14 |
-
torch_dtype=dtype
|
|
|
|
| 15 |
)
|
| 16 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 17 |
return pipe
|
|
@@ -33,5 +44,10 @@ if st.button("Appliquer"):
|
|
| 33 |
ref = Image.open(ref_file).convert("RGB")
|
| 34 |
|
| 35 |
with st.spinner("Génération…"):
|
| 36 |
-
out = pipe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
st.image(out, caption="Résultat", use_column_width=True)
|
|
|
|
| 1 |
+
# streamlit_app.py
|
| 2 |
+
import os
|
| 3 |
import streamlit as st
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
| 6 |
from diffusers import PaintByExamplePipeline
|
| 7 |
|
| 8 |
+
# 👉 Forcer les dossiers de cache dans /app/.cache (où tu as les droits)
|
| 9 |
+
os.environ["HF_HOME"] = "/app/.cache/huggingface"
|
| 10 |
+
os.environ["TRANSFORMERS_CACHE"] = "/app/.cache/transformers"
|
| 11 |
+
os.environ["DIFFUSERS_CACHE"] = "/app/.cache/diffusers"
|
| 12 |
+
|
| 13 |
+
os.makedirs("/app/.cache/huggingface", exist_ok=True)
|
| 14 |
+
os.makedirs("/app/.cache/transformers", exist_ok=True)
|
| 15 |
+
os.makedirs("/app/.cache/diffusers", exist_ok=True)
|
| 16 |
+
|
| 17 |
st.set_page_config(page_title="Paint-By-Example", layout="centered")
|
| 18 |
|
| 19 |
@st.cache_resource(show_spinner=False)
|
|
|
|
| 21 |
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 22 |
pipe = PaintByExamplePipeline.from_pretrained(
|
| 23 |
"Fantasy-Studio/Paint-by-Example",
|
| 24 |
+
torch_dtype=dtype,
|
| 25 |
+
cache_dir=os.environ["DIFFUSERS_CACHE"] # 👉 important : on précise le cache
|
| 26 |
)
|
| 27 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 28 |
return pipe
|
|
|
|
| 44 |
ref = Image.open(ref_file).convert("RGB")
|
| 45 |
|
| 46 |
with st.spinner("Génération…"):
|
| 47 |
+
out = pipe(
|
| 48 |
+
image=image,
|
| 49 |
+
mask_image=mask,
|
| 50 |
+
example_image=ref,
|
| 51 |
+
num_inference_steps=steps
|
| 52 |
+
).images[0]
|
| 53 |
st.image(out, caption="Résultat", use_column_width=True)
|