Spaces:
Sleeping
Sleeping
Kingtous
commited on
Commit
·
9b53dda
1
Parent(s):
df188b5
fix: build
Browse files
app.py
CHANGED
@@ -1,16 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
|
|
|
|
5 |
from simple_lama_inpainting import SimpleLama
|
6 |
|
7 |
-
zero = torch.Tensor([0])
|
8 |
-
print(zero.device)
|
9 |
lama: SimpleLama = SimpleLama(device=zero.device)
|
10 |
|
11 |
-
@spaces.GPU
|
12 |
-
def lama_inpainting(image: Image, mask: Image) -> Image:
|
13 |
-
return lama(image, mask)
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
inpaint.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
+
# import spaces
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
+
import numpy as np
|
7 |
+
import cv2
|
8 |
from simple_lama_inpainting import SimpleLama
|
9 |
|
10 |
+
zero = torch.Tensor([0])
|
11 |
+
print(zero.device) # <-- 'cpu' 🤔
|
12 |
lama: SimpleLama = SimpleLama(device=zero.device)
|
13 |
|
|
|
|
|
|
|
14 |
|
15 |
+
# @spaces.GPU
|
16 |
+
def lama_inpainting(image: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
17 |
+
print(image.shape, mask.shape)
|
18 |
+
res = lama(
|
19 |
+
Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)).convert("RGB"),
|
20 |
+
Image.fromarray(cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)).convert("L"),
|
21 |
+
)
|
22 |
+
return cv2.cvtColor(np.array(res), cv2.COLOR_RGB2BGR)
|
23 |
+
|
24 |
+
|
25 |
+
inpaint = gr.Interface(
|
26 |
+
fn=lama_inpainting,
|
27 |
+
inputs=[gr.Image(label="image"), gr.Image(label="mask")],
|
28 |
+
outputs=gr.Image(),
|
29 |
+
)
|
30 |
inpaint.launch()
|