Update app.py
Browse files21 unmodified lines2223242526272811 unmodified lines4041424344454 unmodified lines5051525354555653 unmodified lines110111112113114115116117118141 unmodified lines26026126226326426526626726826927027127227327427527621 unmodified linesst.session_state.fringe_val = max(0, min(5, st.session_state.fringe_val + delta))# ---------------------------------------------------------------------------# UI Styling# ---------------------------------------------------------------------------st.markdown("""11 unmodified lines.stButton > button:hover { background-color: #4338CA !important; }.stDownloadButton > button { background-color: #10B981 !important; color: white !important; border-radius: 8px !important; border: none !important; font-weight: 600 !important; width: 100%; margin-top: 0.75rem; }.stDownloadButton > button:hover { background-color: #059669 !important; }[data-testid="stImage"] {background-color: #ffffff !important;background-image:4 unmodified linesbackground-size: 16px 16px !important;background-position: 0 0, 8px 0, 8px -8px, 0px 8px !important;border-radius: 8px;border: 1px solid rgba(255, 255, 255, 0.1);}</style>""", unsafe_allow_html=True53 unmodified linesopts.enable_cpu_mem_arena = Falseopts.intra_op_num_threads = 1# Map the list of classes into a dictionary by namesession_dict = {cls.name(): cls for cls in sessions_class}return session_dict["u2net_cloth_seg"]("u2net_cloth_seg", opts)def _mirror_fill(rgb: np.ndarray, garment: np.ndarray, occluded: np.ndarray):141 unmodified linesif method == "Segformer (Pro Garment AI)":out_bytes = segformer_cutout(image_bytes, grow_px)extracted_image = Image.open(io.BytesIO(out_bytes))elif method == "U2Net (Local Occlusion Repair)":out_bytes = u2net_cloth_cutout(image_bytes, repair_occlusion, grow_px)extracted_image = Image.open(io.BytesIO(out_bytes))elif method == "Chroma Key (Studio Green)":extracted_image = chroma_cutout(img_array, key_color_hex, tola, tolb, grow_px)elif method == "Hybrid (AI + Chroma Key)":ai_bytes = u2net_cloth_cutout(image_bytes, repair_occlusion, 0)ai_alpha = np.array(Image.open(io.BytesIO(ai_bytes)).split()[-1])chroma_img = chroma_cutout(img_array, key_color_hex, tola, tolb, grow_px)chroma_alpha = np.array(chroma_img.split()[-1])combined_alpha = np.minimum(ai_alpha, chroma_alpha)extracted_image = chroma_img.copy()extracted_image.putalpha(Image.fromarray(combined_alpha))21 unmodified lines2223242526272811 unmodified lines4041424344454647484 unmodified lines5354555657585953 unmodified lines113114115116117118119120141 unmodified lines26226326426526626726826927027127227327427527627727827928028128228328428528628728828921 unmodified linesst.session_state.fringe_val = max(0, min(5, st.session_state.fringe_val + delta))# ---------------------------------------------------------------------------# UI Styling (Updated Transparency Grid)# ---------------------------------------------------------------------------st.markdown("""11 unmodified lines.stButton > button:hover { background-color: #4338CA !important; }.stDownloadButton > button { background-color: #10B981 !important; color: white !important; border-radius: 8px !important; border: none !important; font-weight: 600 !important; width: 100%; margin-top: 0.75rem; }.stDownloadButton > button:hover { background-color: #059669 !important; }.image-card-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.75rem; text-transform: uppercase; opacity: 0.8; }/* White/Gray Transparency Grid */[data-testid="stImage"] {background-color: #ffffff !important;background-image:4 unmodified linesbackground-size: 16px 16px !important;background-position: 0 0, 8px 0, 8px -8px, 0px 8px !important;border-radius: 8px;border: 1px solid rgba(128, 128, 128, 0.2);}</style>""", unsafe_allow_html=True53 unmodified linesopts.enable_cpu_mem_arena = Falseopts.intra_op_num_threads = 1# Map the list of classes into a dictionary by name to prevent index errorssession_dict = {cls.name(): cls for cls in sessions_class}return session_dict["u2net_cloth_seg"]("u2net_cloth_seg", opts)def _mirror_fill(rgb: np.ndarray, garment: np.ndarray, occluded: np.ndarray):141 unmodified linesif method == "Segformer (Pro Garment AI)":out_bytes = segformer_cutout(image_bytes, grow_px)extracted_image = Image.open(io.BytesIO(out_bytes))elif method == "U2Net (Local Occlusion Repair)":out_bytes = u2net_cloth_cutout(image_bytes, repair_occlusion, grow_px)extracted_image = Image.open(io.BytesIO(out_bytes))elif method == "Chroma Key (Studio Green)":extracted_image = chroma_cutout(img_array, key_color_hex, tola, tolb, grow_px)elif method == "Hybrid (AI + Chroma Key)":ai_bytes = u2net_cloth_cutout(image_bytes, repair_occlusion, grow_px)ai_alpha = np.array(Image.open(io.BytesIO(ai_bytes)).split()[-1])chroma_img = chroma_cutout(img_array, key_color_hex, tola, tolb, grow_px)chroma_alpha = np.array(chroma_img.split()[-1])# Combine masks mathematicallycombined_alpha = np.minimum(ai_alpha, chroma_alpha)# Force active fringe erasureif grow_px > 0:combined_alpha = cv2.erode(combined_alpha, np.ones((3, 3), np.uint8), iterations=grow_px)extracted_image = chroma_img.copy()extracted_image.putalpha(Image.fromarray(combined_alpha))
app.py+18-5