flixnetf435's picture
Update app.py
f9c92a8 verified
Raw
History Blame Contribute Delete
3.42 kB
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)