src/streamlit_app.py
Browse files1234567891 unmodified line1112131415161715 unmodified lines3334353637# app_paint_by_example.pyimport streamlit as stfrom PIL import Imageimport torchfrom diffusers import PaintByExamplePipelinest.set_page_config(page_title="Paint-By-Example", layout="centered")@st.cache_resource(show_spinner=False)1 unmodified linedtype = torch.float16 if torch.cuda.is_available() else torch.float32pipe = PaintByExamplePipeline.from_pretrained("Fantasy-Studio/Paint-by-Example",torch_dtype=dtype)pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")return pipe15 unmodified linesref = 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]st.image(out, caption="Résultat", use_column_width=True)123456789101112131415161718191 unmodified line212223242526272815 unmodified lines44454647484950515253# 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 linedtype = torch.float16 if torch.cuda.is_available() else torch.float32pipe = PaintByExamplePipeline.from_pretrained("Fantasy-Studio/Paint-by-Example",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 linesref = 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]st.image(out, caption="Résultat", use_column_width=True)
src/streamlit_app.py+19-3