import streamlit as st from rembg import remove from PIL import Image import io import numpy as np from streamlit_image_comparison import image_comparison # 1. إعدادات الصفحة st.set_page_config(page_title="MagicBG - Professional AI Tool", page_icon="✂️") # 2. تنسيقات CSS (الحفاظ على الهوية البصرية اللي صاوبنا) st.markdown(""" """, unsafe_allow_html=True) # 3. الواجهة الرئيسية st.title("✂️ MagicBG") st.markdown("### High-Precision AI Background Removal") st.divider() # 4. رفع ومعالجة الصور uploaded_file = st.file_uploader("Upload your image", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: input_image = Image.open(uploaded_file).convert("RGB") with st.spinner("Magic is happening... Please wait ✨"): try: # معالجة الصورة بالذكاء الاصطناعي input_array = np.array(input_image) output_array = remove(input_array) result_image = Image.fromarray(output_array) # --- ميزة المنزلق التفاعلي الجديد --- st.markdown("### ↔️ Move the slider to see the magic") image_comparison( img1=input_image, img2=result_image, label1="Original", label2="MagicBG Result", starting_position=50, show_labels=True, make_responsive=True, in_memory=True ) # زر التحميل (HD) st.divider() buf = io.BytesIO() result_image.save(buf, format="PNG") st.download_button( label="🚀 Download Transparent Image (HD)", data=buf.getvalue(), file_name=f"MagicBG_{uploaded_file.name}.png", mime="image/png" ) except Exception as e: st.error(f"Opps! Something went wrong: {e}") # 5. بطاقة التعريف والدعم (كاملة بجميع معلوماتك) st.divider() st.markdown("""

👨‍💻 Developer Profile

Name: Youssef Oumalk

Specialty: Python & AI Solutions


🌍 Support My Projects

Bank: Al Barid Bank
RIB: 350810000000001240198814

© 2024 MagicBG | Designed with ❤️ by Youssef Oumalk
""", unsafe_allow_html=True)