Update app.py
Browse files10 unmodified lines11121314141516114 unmodified lines13113213313513413513621 unmodified lines158159160163164161162163112 unmodified lines2762772782832792802812822872832842852861 unmodified line28828929029529129229329420 unmodified lines3153163173223183193203212 unmodified lines32432532633132732832933010 unmodified lines# ---------------------------------------------------------------------------st.set_page_config(layout="wide", page_title="Garment Extractor Pro", page_icon="✂️", initial_sidebar_state="expanded")
# Initialize state at the very top to prevent runtime routing crashesif "fringe_val" not in st.session_state: st.session_state.fringe_val = 0
114 unmodified lines
MAX_MASK_EDGE = 1024
# MEMORY FIX: max_entries=1 drops the old neural network before loading a new one.@st.cache_resource(show_spinner=False, max_entries=1)def load_ai_session(model_name: str): import onnxruntime as ort21 unmodified lines if model_name == "u2net_cloth_seg": rgb_mask = raw_mask.convert("RGB") r, g, b = rgb_mask.split() # Red = Upper Clothes, Green = Lower Clothes. Drops the Blue skin channel. clothes_only = np.maximum(np.array(r), np.array(g)) mask = Image.fromarray(clothes_only).convert("L") else:112 unmodified lines st.markdown("<p style='font-size: 0.9rem; font-weight: 500; margin-bottom: 0;'>Fringe Eraser (px)</p>", unsafe_allow_html=True) col_min, col_slide, col_plus = st.columns([1, 4, 1]) with col_min: st.button("−", on_click=step_fringe, args=(-1,), use_container_width=True, key="btn_minus") st.button("−", on_click=step_fringe, args=(-1,), width="stretch", key="btn_minus") with col_slide: grow_px = st.slider("Fringe", 0, 5, key="fringe_val", label_visibility="collapsed") with col_plus: st.button("+", on_click=step_fringe, args=(1,), use_container_width=True, key="btn_plus") st.button("+", on_click=step_fringe, args=(1,), width="stretch", key="btn_plus")
# 3. Process & Render Result1 unmodified line
with col1: st.markdown('<div class="image-card-title">Source Image</div>', unsafe_allow_html=True) st.image(original_image, use_container_width=True) st.image(original_image, width="stretch")
with col2: st.markdown('<div class="image-card-title">Extraction Result</div>', unsafe_allow_html=True)20 unmodified lines extracted_image = chroma_img.copy() extracted_image.putalpha(Image.fromarray(combined_alpha))
st.image(extracted_image, use_container_width=True) st.image(extracted_image, width="stretch") buf = io.BytesIO() extracted_image.save(buf, format="PNG")2 unmodified lines data=buf.getvalue(), file_name="product_asset.png", mime="image/png", use_container_width=True width="stretch" ) except ModuleNotFoundError as exc:app.py+5-9