src/streamlit_app.py
Browse files1123456789101112131415161718191 unmodified line21222314242526272815 unmodified lines4445463647484950515253# app_paint_by_example.py# streamlit_app.pyimport osimport streamlit as stfrom PIL import Imageimport torchfrom diffusers import PaintByExamplePipeline
# 👉 Forcer les dossiers de cache dans /app/.cache (où tu as les droits)os.environ["HF_HOME"] = "/app/.cache/huggingface"os.environ["TRANSFORMERS_CACHE"] = "/app/.cache/transformers"os.environ["DIFFUSERS_CACHE"] = "/app/.cache/diffusers"
os.makedirs("/app/.cache/huggingface", exist_ok=True)os.makedirs("/app/.cache/transformers", exist_ok=True)os.makedirs("/app/.cache/diffusers", exist_ok=True)
st.set_page_config(page_title="Paint-By-Example", layout="centered")
@st.cache_resource(show_spinner=False)1 unmodified line dtype = torch.float16 if torch.cuda.is_available() else torch.float32 pipe = PaintByExamplePipeline.from_pretrained( "Fantasy-Studio/Paint-by-Example", torch_dtype=dtype torch_dtype=dtype, cache_dir=os.environ["DIFFUSERS_CACHE"] # 👉 important : on précise le cache ) pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") return pipe15 unmodified lines ref = Image.open(ref_file).convert("RGB")
with st.spinner("Génération…"): out = pipe(image=image, mask_image=mask, example_image=ref, num_inference_steps=steps).images[0] out = pipe( image=image, mask_image=mask, example_image=ref, num_inference_steps=steps ).images[0] st.image(out, caption="Résultat", use_column_width=True)src/streamlit_app.py+19-3