Enhance UI styles and layout in app.py
Browse filesRefactor styles and improve UI elements for better aesthetics and functionality.
15 unmodified lines161718192021222324252627282930313233343536373839404142434445464748495051525354555657585925 unmodified lines85868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312431 unmodified lines15615715815916016116234 unmodified lines1971981992002012022031 unmodified line20520620720820921021112 unmodified lines2242252262272282292304 unmodified lines23523623723823924024123 unmodified lines26526626726826927027127227327427527627727827928028128228328428528628715 unmodified lines<style>@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');html, body, [class*="css"] {font-family: 'Inter', sans-serif;background-color: #F9FAFB;color: #111827;}.block-container { padding-top: 2rem !important; max-width: 1400px; }header { visibility: hidden; }footer { visibility: hidden; }.app-header {margin-bottom: 2rem;padding-bottom: 1rem;border-bottom: 1px solid #E5E7EB;}.app-title {font-weight: 700;font-size: 2.25rem;color: #111827;margin-bottom: 0.25rem;}.app-subtitle {font-size: 1rem;color: #6B7280;}[data-testid="stSidebar"] {background-color: #FFFFFF;border-right: 1px solid #E5E7EB;}.sidebar-header {font-weight: 600;font-size: 1.1rem;margin-top: 1rem;margin-bottom: 0.5rem;color: #374151;}.stButton > button {background-color: #4F46E5 !important;color: white !important;25 unmodified linesbox-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2) !important;}.image-card {background: #FFFFFF;padding: 1rem;border-radius: 12px;box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);border: 1px solid #E5E7EB;margin-bottom: 1rem;}.image-card-title {font-weight: 600;font-size: 0.9rem;color: #4B5563;margin-bottom: 0.75rem;text-transform: uppercase;letter-spacing: 0.05em;}[data-testid="stFileUploaderDropzone"] {border-radius: 12px;border: 2px dashed #D1D5DB;background-color: #FFFFFF;transition: all 0.2s;}[data-testid="stFileUploaderDropzone"]:hover {border-color: #4F46E5;background-color: #F5F3FF;}</style>""",unsafe_allow_html=True,)# ---------------------------------------------------------------------------# Core Logic: AI Cutout (Expanded Model Tiers)# ---------------------------------------------------------------------------AI_MODELS = {"u2netp (Fast & Light)": "u2netp",31 unmodified linesmask = channels[-1] if len(channels) == 4 else raw_mask.convert("L")mask = mask.resize(source.size, Image.LANCZOS)# Fringe Removal (Erosion)if grow_px > 0:mask_arr = np.array(mask)kernel = np.ones((3, 3), np.uint8)34 unmodified linesalpha_f = 1.0 - maskfinal_rgb = img_array.copy()# Spill Suppressionedge_mask = (alpha_f > 0.05) & (alpha_f < 0.95)if target_color[1] > target_color[0] and target_color[1] > target_color[2]:r, g, b = final_rgb[:,:,0].astype(np.float32), final_rgb[:,:,1].astype(np.float32), final_rgb[:,:,2].astype(np.float32)1 unmodified linesuppressed_g = np.where(edge_mask & (g > max_green), max_green, g)final_rgb[:,:,1] = suppressed_g.astype(np.uint8)# Fringe removalif grow_px > 0:fg_binary = (alpha_f > 0.5).astype(np.uint8)core = cv2.erode(fg_binary, np.ones((3, 3), np.uint8), iterations=grow_px)12 unmodified lines# ---------------------------------------------------------------------------st.markdown('<div class="app-header"><div class="app-title">Garment Extractor Pro</div><div class="app-subtitle">Create clean, transparent product assets instantly.</div></div>', unsafe_allow_html=True)# 1. Image upload must happen first so the sidebar can dynamically read the background hexuploaded_file = st.file_uploader("Upload product photo to begin", type=["png", "jpg", "jpeg"], label_visibility="collapsed")if uploaded_file is None:4 unmodified linesoriginal_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")img_array = np.array(original_image)# 2. Sidebar renders after image is loadedwith st.sidebar:st.markdown('<div class="sidebar-header">Engine Settings</div>', unsafe_allow_html=True)method = st.radio("Processing Engine", ["AI Engine (Auto)", "Chroma Key (Studio Green)"], label_visibility="collapsed")23 unmodified linescol1, col2 = st.columns(2, gap="large")with col1:st.markdown("""<div class="image-card"><div class="image-card-title">Source Image</div></div>""", unsafe_allow_html=True)st.image(original_image, use_container_width=True)with col2:st.markdown("""<div class="image-card"><div class="image-card-title">Extraction Result</div></div>""", unsafe_allow_html=True)try:if method == "AI Engine (Auto)":15 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535425 unmodified lines808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112231 unmodified lines15415515615715815934 unmodified lines1941951961971981991 unmodified line20120220320420520612 unmodified lines2192202212222232244 unmodified lines22923023123223323423 unmodified lines25825926026126226326426526626726815 unmodified lines<style>@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');/* Base Typography */html, body, [class*="css"] {font-family: 'Inter', sans-serif;}.block-container { padding-top: 2rem !important; max-width: 1400px; }header { visibility: hidden; }footer { visibility: hidden; }/* Layout & Headers */.app-header {margin-bottom: 2rem;padding-bottom: 1rem;border-bottom: 1px solid rgba(128, 128, 128, 0.2);}.app-title {font-weight: 700;font-size: 2.25rem;margin-bottom: 0.25rem;}.app-subtitle {font-size: 1rem;opacity: 0.7;}.sidebar-header {font-weight: 600;font-size: 1.1rem;margin-top: 1rem;margin-bottom: 0.5rem;}/* Buttons */.stButton > button {background-color: #4F46E5 !important;color: white !important;25 unmodified linesbox-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2) !important;}/* Image Containers & Checkerboard Background for Transparency */[data-testid="stImage"] {background-color: #ffffff;background-image:linear-gradient(45deg, #e5e5e5 25%, transparent 25%),linear-gradient(135deg, #e5e5e5 25%, transparent 25%),linear-gradient(45deg, transparent 75%, #e5e5e5 75%),linear-gradient(135deg, transparent 75%, #e5e5e5 75%);background-size: 20px 20px;background-position: 0 0, 10px 0, 10px -10px, 0px 10px;border-radius: 8px;overflow: hidden;border: 1px solid rgba(128, 128, 128, 0.2);}.image-card-title {font-weight: 600;font-size: 0.9rem;margin-bottom: 0.75rem;text-transform: uppercase;letter-spacing: 0.05em;opacity: 0.8;}/* File Uploader */[data-testid="stFileUploaderDropzone"] {border-radius: 12px;border: 2px dashed rgba(128, 128, 128, 0.4);transition: all 0.2s;}</style>""",unsafe_allow_html=True,)# ---------------------------------------------------------------------------# Core Logic: AI Cutout# ---------------------------------------------------------------------------AI_MODELS = {"u2netp (Fast & Light)": "u2netp",31 unmodified linesmask = channels[-1] if len(channels) == 4 else raw_mask.convert("L")mask = mask.resize(source.size, Image.LANCZOS)if grow_px > 0:mask_arr = np.array(mask)kernel = np.ones((3, 3), np.uint8)34 unmodified linesalpha_f = 1.0 - maskfinal_rgb = img_array.copy()edge_mask = (alpha_f > 0.05) & (alpha_f < 0.95)if target_color[1] > target_color[0] and target_color[1] > target_color[2]:r, g, b = final_rgb[:,:,0].astype(np.float32), final_rgb[:,:,1].astype(np.float32), final_rgb[:,:,2].astype(np.float32)1 unmodified linesuppressed_g = np.where(edge_mask & (g > max_green), max_green, g)final_rgb[:,:,1] = suppressed_g.astype(np.uint8)if grow_px > 0:fg_binary = (alpha_f > 0.5).astype(np.uint8)core = cv2.erode(fg_binary, np.ones((3, 3), np.uint8), iterations=grow_px)12 unmodified lines# ---------------------------------------------------------------------------st.markdown('<div class="app-header"><div class="app-title">Garment Extractor Pro</div><div class="app-subtitle">Create clean, transparent product assets instantly.</div></div>', unsafe_allow_html=True)uploaded_file = st.file_uploader("Upload product photo to begin", type=["png", "jpg", "jpeg"], label_visibility="collapsed")if uploaded_file is None:4 unmodified linesoriginal_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")img_array = np.array(original_image)with st.sidebar:st.markdown('<div class="sidebar-header">Engine Settings</div>', unsafe_allow_html=True)method = st.radio("Processing Engine", ["AI Engine (Auto)", "Chroma Key (Studio Green)"], label_visibility="collapsed")23 unmodified linescol1, col2 = st.columns(2, gap="large")with col1:st.markdown('<div class="image-card-title">Source Image</div>', unsafe_allow_html=True)st.image(original_image, use_container_width=True)with col2:st.markdown('<div class="image-card-title">Extraction Result</div>', unsafe_allow_html=True)try:if method == "AI Engine (Auto)":
app.py+25-44