File size: 3,418 Bytes
4a45084
 
 
 
d566478
f9c92a8
4a45084
abd7864
4a45084
 
f9c92a8
4a45084
 
 
 
abd7864
 
4a45084
 
 
 
abd7864
4a45084
 
 
 
f9c92a8
d566478
4a45084
 
d566478
4a45084
f9c92a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a45084
f9c92a8
abd7864
d566478
abd7864
 
 
 
 
 
 
 
 
 
 
 
 
4a45084
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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("""
    <style>
    .main { background-color: #f8f9fa; }
    .stButton>button { 
        width: 100%; border-radius: 8px; background-color: #007bff; 
        color: white; height: 3.5em; font-weight: bold; font-size: 18px;
    }
    </style>
    """, 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("""
    <div style="background-color: #ffffff; padding: 20px; border-radius: 15px; border: 1px solid #e1e4e8; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-top: 50px;">
        <h3 style="color: #007bff; margin-bottom: 10px;">👨‍💻 Developer Profile</h3>
        <p style="font-size: 18px; margin: 0;"><b>Name:</b> Youssef Oumalk</p>
        <p style="color: #666;">Specialty: Python & AI Solutions</p>
        <hr style="border: 0; border-top: 1px solid #eee; margin: 15px 0;">
        <p style="font-size: 14px; color: #28a745;"><b>🌍 Support My Projects</b></p>
        <p style="font-size: 13px; color: #444; background: #f1f1f1; padding: 10px; border-radius: 5px;">
            <b>Bank:</b> Al Barid Bank <br>
            <b>RIB:</b> <code>350810000000001240198814</code>
        </p>
    </div>
    <div style="text-align: center; padding: 20px; color: #888; font-size: 12px;">
        © 2024 MagicBG | Designed with ❤️ by Youssef Oumalk
    </div>
    """, unsafe_allow_html=True)