Update app.py
Browse files
app.py
CHANGED
|
@@ -10,15 +10,13 @@ import tempfile
|
|
| 10 |
# Initialize the SimpleLama model
|
| 11 |
simple_lama = SimpleLama()
|
| 12 |
def inpaint_image(input_data):
|
| 13 |
-
if input_data is None:
|
| 14 |
raise gr.Error("Please upload an image and draw a mask.")
|
| 15 |
|
| 16 |
-
# input_data is a dict with '
|
| 17 |
-
image = input_data['
|
| 18 |
-
mask
|
| 19 |
-
|
| 20 |
-
# In Gradio sketch, mask is white where drawn (to inpaint), black elsewhere
|
| 21 |
-
# But ensure it's binary if needed, though SimpleLama likely handles grayscale
|
| 22 |
|
| 23 |
# Perform inpainting
|
| 24 |
result = simple_lama(image, mask)
|
|
@@ -29,9 +27,8 @@ def inpaint_image(input_data):
|
|
| 29 |
tmp_path = tmp.name
|
| 30 |
|
| 31 |
return result, tmp_path
|
| 32 |
-
inputs = [gr.
|
| 33 |
label="Upload and Mask Image",
|
| 34 |
-
tool="sketch",
|
| 35 |
brush=gr.Brush(colors=["#FFFFFF"], default_color="#FFFFFF"),
|
| 36 |
interactive=True
|
| 37 |
)]
|
|
@@ -41,7 +38,7 @@ examples = [
|
|
| 41 |
]
|
| 42 |
# For HF Spaces, requirements.txt would include:
|
| 43 |
# simple-lama-inpainting
|
| 44 |
-
# gradio
|
| 45 |
# pillow
|
| 46 |
# torch (if not included in simple-lama)
|
| 47 |
title = "LaMa Image Inpainting"
|
|
|
|
| 10 |
# Initialize the SimpleLama model
|
| 11 |
simple_lama = SimpleLama()
|
| 12 |
def inpaint_image(input_data):
|
| 13 |
+
if input_data is None or not input_data['layers']:
|
| 14 |
raise gr.Error("Please upload an image and draw a mask.")
|
| 15 |
|
| 16 |
+
# input_data is a dict with 'background', 'layers', 'composite'
|
| 17 |
+
image = input_data['background'].convert("RGB")
|
| 18 |
+
# Assume first layer is the mask drawn with white brush
|
| 19 |
+
mask = input_data['layers'][0].convert("L")
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Perform inpainting
|
| 22 |
result = simple_lama(image, mask)
|
|
|
|
| 27 |
tmp_path = tmp.name
|
| 28 |
|
| 29 |
return result, tmp_path
|
| 30 |
+
inputs = [gr.ImageEditor(
|
| 31 |
label="Upload and Mask Image",
|
|
|
|
| 32 |
brush=gr.Brush(colors=["#FFFFFF"], default_color="#FFFFFF"),
|
| 33 |
interactive=True
|
| 34 |
)]
|
|
|
|
| 38 |
]
|
| 39 |
# For HF Spaces, requirements.txt would include:
|
| 40 |
# simple-lama-inpainting
|
| 41 |
+
# gradio>=4.39.0
|
| 42 |
# pillow
|
| 43 |
# torch (if not included in simple-lama)
|
| 44 |
title = "LaMa Image Inpainting"
|