Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,18 +36,23 @@ def process(image):
|
|
| 36 |
image.putalpha(mask)
|
| 37 |
return image
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
|
|
|
| 43 |
|
|
|
|
| 44 |
if tab == "رفع صورة":
|
| 45 |
uploaded_file = st.file_uploader("ارفع صورة:")
|
| 46 |
if uploaded_file is not None:
|
| 47 |
image = Image.open(uploaded_file).convert("RGB")
|
| 48 |
-
st.image(image, caption="الصورة الأصلية", use_column_width=True)
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
elif tab == "رابط صورة":
|
| 53 |
url = st.text_input("أدخل رابط الصورة:")
|
|
@@ -55,18 +60,49 @@ elif tab == "رابط صورة":
|
|
| 55 |
try:
|
| 56 |
response = requests.get(url)
|
| 57 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 58 |
-
st.image(image, caption="الصورة الأصلية", use_column_width=True)
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
-
st.error(f"خطأ أثناء تحميل الصورة: {e}")
|
| 63 |
|
| 64 |
elif tab == "ملف":
|
| 65 |
uploaded_file = st.file_uploader("ارفع ملف:")
|
| 66 |
if uploaded_file is not None:
|
| 67 |
image = Image.open(uploaded_file).convert("RGB")
|
| 68 |
-
|
|
|
|
| 69 |
output_path = uploaded_file.name.rsplit(".", 1)[0] + ".png"
|
| 70 |
processed_image.save(output_path)
|
| 71 |
-
st.image(processed_image, caption="الصورة المعالجة", use_column_width=True)
|
| 72 |
-
st.download_button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
image.putalpha(mask)
|
| 37 |
return image
|
| 38 |
|
| 39 |
+
# إعداد واجهة المستخدم
|
| 40 |
+
st.set_page_config(page_title="أداة إزالة الخلفية", layout="centered")
|
| 41 |
+
st.title("🌟 أداة إزالة الخلفية")
|
| 42 |
|
| 43 |
+
# اختيار نوع الإدخال
|
| 44 |
+
st.subheader("اختر طريقة إدخال الصورة:")
|
| 45 |
+
tab = st.radio("", ["رفع صورة", "رابط صورة", "ملف"])
|
| 46 |
|
| 47 |
+
# عملية إزالة الخلفية
|
| 48 |
if tab == "رفع صورة":
|
| 49 |
uploaded_file = st.file_uploader("ارفع صورة:")
|
| 50 |
if uploaded_file is not None:
|
| 51 |
image = Image.open(uploaded_file).convert("RGB")
|
| 52 |
+
st.image(image, caption="📷 الصورة الأصلية", use_column_width=True)
|
| 53 |
+
with st.spinner("🔄 يتم إزالة الخلفية، يرجى الانتظار..."):
|
| 54 |
+
processed_image = process(image)
|
| 55 |
+
st.image(processed_image, caption="✨ الصورة المعالجة", use_column_width=True)
|
| 56 |
|
| 57 |
elif tab == "رابط صورة":
|
| 58 |
url = st.text_input("أدخل رابط الصورة:")
|
|
|
|
| 60 |
try:
|
| 61 |
response = requests.get(url)
|
| 62 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 63 |
+
st.image(image, caption="📷 الصورة الأصلية", use_column_width=True)
|
| 64 |
+
with st.spinner("🔄 يتم إزالة الخلفية، يرجى الانتظار..."):
|
| 65 |
+
processed_image = process(image)
|
| 66 |
+
st.image(processed_image, caption="✨ الصورة المعالجة", use_column_width=True)
|
| 67 |
except Exception as e:
|
| 68 |
+
st.error(f"❌ خطأ أثناء تحميل الصورة: {e}")
|
| 69 |
|
| 70 |
elif tab == "ملف":
|
| 71 |
uploaded_file = st.file_uploader("ارفع ملف:")
|
| 72 |
if uploaded_file is not None:
|
| 73 |
image = Image.open(uploaded_file).convert("RGB")
|
| 74 |
+
with st.spinner("🔄 يتم إزالة الخلفية، يرجى الانتظار..."):
|
| 75 |
+
processed_image = process(image)
|
| 76 |
output_path = uploaded_file.name.rsplit(".", 1)[0] + ".png"
|
| 77 |
processed_image.save(output_path)
|
| 78 |
+
st.image(processed_image, caption="✨ الصورة المعالجة", use_column_width=True)
|
| 79 |
+
st.download_button(
|
| 80 |
+
"📥 تحميل الصورة المعالجة",
|
| 81 |
+
data=open(output_path, "rb"),
|
| 82 |
+
file_name=output_path,
|
| 83 |
+
mime="image/png",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# تحسين الألوان والخط
|
| 87 |
+
st.markdown(
|
| 88 |
+
"""
|
| 89 |
+
<style>
|
| 90 |
+
body {
|
| 91 |
+
background-color: #f8f9fa;
|
| 92 |
+
}
|
| 93 |
+
.stButton>button {
|
| 94 |
+
background-color: #4CAF50;
|
| 95 |
+
color: white;
|
| 96 |
+
border-radius: 10px;
|
| 97 |
+
}
|
| 98 |
+
.stRadio>div>label {
|
| 99 |
+
font-size: 16px;
|
| 100 |
+
color: #333;
|
| 101 |
+
}
|
| 102 |
+
.stSpinner {
|
| 103 |
+
color: #FF5733;
|
| 104 |
+
}
|
| 105 |
+
</style>
|
| 106 |
+
""",
|
| 107 |
+
unsafe_allow_html=True,
|
| 108 |
+
)
|