Spaces:
Runtime error
Runtime error
Commit
·
e7953d7
1
Parent(s):
41f1dd9
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import cv2
|
|
7 |
import numpy as np
|
8 |
|
9 |
from camera_input_live import camera_input_live
|
10 |
-
|
11 |
st.set_page_config(layout="wide")
|
12 |
|
13 |
|
@@ -40,7 +40,9 @@ def get_mask(image_mask: np.ndarray) -> np.ndarray:
|
|
40 |
if mask.sum() > 0:
|
41 |
mask = mask * 1
|
42 |
# 3 channels
|
43 |
-
mask = np.stack([mask, mask, mask], axis=2)
|
|
|
|
|
44 |
return mask
|
45 |
|
46 |
|
@@ -69,7 +71,7 @@ def make_input_fields():
|
|
69 |
def decode_image(image):
|
70 |
cv2_img = cv2.imdecode(np.frombuffer(image, np.uint8), cv2.IMREAD_COLOR)
|
71 |
cv2_img = cv2.cvtColor(cv2_img, cv2.COLOR_BGR2RGB)
|
72 |
-
image = Image.fromarray(cv2_img).convert("RGB")
|
73 |
return image
|
74 |
|
75 |
if __name__ == "__main__":
|
@@ -91,12 +93,17 @@ if __name__ == "__main__":
|
|
91 |
image = decode_image(webcam.getvalue())
|
92 |
|
93 |
canvas = make_canvas(image)
|
94 |
-
|
|
|
95 |
mask = get_mask(np.array(canvas.image_data))
|
|
|
|
|
|
|
96 |
|
97 |
with colB:
|
98 |
st.write("## Generated image")
|
99 |
st.write("The generated image will appear here.")
|
100 |
if webcam:
|
101 |
st.image(webcam)
|
102 |
-
|
|
|
|
7 |
import numpy as np
|
8 |
|
9 |
from camera_input_live import camera_input_live
|
10 |
+
from inference import inpainting
|
11 |
st.set_page_config(layout="wide")
|
12 |
|
13 |
|
|
|
40 |
if mask.sum() > 0:
|
41 |
mask = mask * 1
|
42 |
# 3 channels
|
43 |
+
mask = np.stack([mask, mask, mask], axis=2)*255
|
44 |
+
mask = mask.astype(np.uint8)
|
45 |
+
mask = Image.fromarray(mask).convert("RGB")
|
46 |
return mask
|
47 |
|
48 |
|
|
|
71 |
def decode_image(image):
|
72 |
cv2_img = cv2.imdecode(np.frombuffer(image, np.uint8), cv2.IMREAD_COLOR)
|
73 |
cv2_img = cv2.cvtColor(cv2_img, cv2.COLOR_BGR2RGB)
|
74 |
+
image = Image.fromarray(cv2_img).convert("RGB").resize((512, 512))
|
75 |
return image
|
76 |
|
77 |
if __name__ == "__main__":
|
|
|
93 |
image = decode_image(webcam.getvalue())
|
94 |
|
95 |
canvas = make_canvas(image)
|
96 |
+
|
97 |
+
if st.button("Inpaint"):
|
98 |
mask = get_mask(np.array(canvas.image_data))
|
99 |
+
result = inpainting(image, mask_image, prompt, negative_prompt)
|
100 |
+
else:
|
101 |
+
result = None
|
102 |
|
103 |
with colB:
|
104 |
st.write("## Generated image")
|
105 |
st.write("The generated image will appear here.")
|
106 |
if webcam:
|
107 |
st.image(webcam)
|
108 |
+
if result:
|
109 |
+
st.image(result)
|