Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,38 +50,32 @@ def apply_latent_poisoning(latent, strength=0.3):
|
|
| 50 |
|
| 51 |
return poisoned_latent
|
| 52 |
|
| 53 |
-
def encode_image_to_base64(image):
|
| 54 |
-
buffered = io.BytesIO()
|
| 55 |
-
image.save(buffered, format="JPEG")
|
| 56 |
-
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 57 |
-
|
| 58 |
def process_image(input_image, strength=0.3):
|
|
|
|
|
|
|
|
|
|
| 59 |
# استخراج التمثيل الكامن
|
| 60 |
latent = image_to_latent(input_image)
|
| 61 |
|
| 62 |
# تطبيق التشويش على الفضاء الكامن
|
| 63 |
-
poisoned_latent = apply_latent_poisoning(latent, strength)
|
| 64 |
|
| 65 |
# إعادة بناء الصورة
|
| 66 |
protected_image = latent_to_image(poisoned_latent)
|
| 67 |
|
| 68 |
return protected_image
|
| 69 |
|
| 70 |
-
# تعريف واجهة ال
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
protect_btn.click(fn=process_image, inputs=[input_image, strength], outputs=output_image)
|
| 82 |
-
|
| 83 |
-
# تعريف API للاستخدام عبر REST
|
| 84 |
-
gr.Interface.load("interface", inputs=[input_image, strength], outputs=output_image, title="Latent Diffusion API")
|
| 85 |
|
| 86 |
# تشغيل التطبيق
|
| 87 |
-
|
|
|
|
| 50 |
|
| 51 |
return poisoned_latent
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
def process_image(input_image, strength=0.3):
|
| 54 |
+
if input_image is None:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
# استخراج التمثيل الكامن
|
| 58 |
latent = image_to_latent(input_image)
|
| 59 |
|
| 60 |
# تطبيق التشويش على الفضاء الكامن
|
| 61 |
+
poisoned_latent = apply_latent_poisoning(latent, float(strength))
|
| 62 |
|
| 63 |
# إعادة بناء الصورة
|
| 64 |
protected_image = latent_to_image(poisoned_latent)
|
| 65 |
|
| 66 |
return protected_image
|
| 67 |
|
| 68 |
+
# تعريف واجهة Gradio الرئيسية
|
| 69 |
+
iface = gr.Interface(
|
| 70 |
+
fn=process_image,
|
| 71 |
+
inputs=[
|
| 72 |
+
gr.Image(type="pil", label="الصورة الأصلية"),
|
| 73 |
+
gr.Slider(minimum=0.1, maximum=0.5, value=0.3, step=0.1, label="قوة الحماية")
|
| 74 |
+
],
|
| 75 |
+
outputs=gr.Image(type="pil", label="الصورة المحمية"),
|
| 76 |
+
title="حماية الصور باستخدام الفضاء الكامن المعكوس",
|
| 77 |
+
description="قم برفع صورة وتحديد قوة الحماية لتطبيق تقنية الفضاء الكامن المعكوس"
|
| 78 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# تشغيل التطبيق
|
| 81 |
+
iface.launch()
|