Spaces:
Sleeping
Sleeping
Commit
·
26987c4
1
Parent(s):
db1433d
up 3
Browse files- app.py +11 -6
- models.py +4 -3
- preprocessing.py +5 -4
app.py
CHANGED
|
@@ -3,9 +3,9 @@ import io
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
|
| 7 |
from models import make_image_controlnet, make_inpainting
|
| 8 |
-
from preprocessing import
|
| 9 |
|
| 10 |
def image_to_byte_array(image: Image) -> bytes:
|
| 11 |
# BytesIO is a fake file stored in memory
|
|
@@ -20,15 +20,19 @@ def predict(input_img1,
|
|
| 20 |
input_img2,
|
| 21 |
positive_prompt,
|
| 22 |
negative_prompt,
|
| 23 |
-
num_of_images
|
|
|
|
| 24 |
):
|
| 25 |
|
| 26 |
print("predict")
|
| 27 |
# input_img1 = Image.fromarray(input_img1)
|
| 28 |
# input_img2 = Image.fromarray(input_img2)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
canvas_mask = np.array(input_img2)
|
| 34 |
mask = get_mask(canvas_mask)
|
|
@@ -56,7 +60,8 @@ app = gr.Interface(
|
|
| 56 |
gr.Image(label="mask", sources=['upload'], type="pil"),
|
| 57 |
gr.Textbox(label="positive_prompt"),
|
| 58 |
gr.Textbox(label="negative_prompt"),
|
| 59 |
-
gr.Number(label="num_of_images")
|
|
|
|
| 60 |
],
|
| 61 |
outputs= [
|
| 62 |
gr.Image(label="resp0"),
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
import config
|
| 7 |
from models import make_image_controlnet, make_inpainting
|
| 8 |
+
from preprocessing import get_mask
|
| 9 |
|
| 10 |
def image_to_byte_array(image: Image) -> bytes:
|
| 11 |
# BytesIO is a fake file stored in memory
|
|
|
|
| 20 |
input_img2,
|
| 21 |
positive_prompt,
|
| 22 |
negative_prompt,
|
| 23 |
+
num_of_images,
|
| 24 |
+
resolution
|
| 25 |
):
|
| 26 |
|
| 27 |
print("predict")
|
| 28 |
# input_img1 = Image.fromarray(input_img1)
|
| 29 |
# input_img2 = Image.fromarray(input_img2)
|
| 30 |
|
| 31 |
+
config.WIDTH = resolution
|
| 32 |
+
config.HEIGHT = resolution
|
| 33 |
+
|
| 34 |
+
input_img1 = input_img1.resize((config.WIDTH, config.HEIGHT))
|
| 35 |
+
input_img2 = input_img2.resize((config.WIDTH, config.HEIGHT))
|
| 36 |
|
| 37 |
canvas_mask = np.array(input_img2)
|
| 38 |
mask = get_mask(canvas_mask)
|
|
|
|
| 60 |
gr.Image(label="mask", sources=['upload'], type="pil"),
|
| 61 |
gr.Textbox(label="positive_prompt"),
|
| 62 |
gr.Textbox(label="negative_prompt"),
|
| 63 |
+
gr.Number(label="num_of_images"),
|
| 64 |
+
gr.Number(label="resolution")
|
| 65 |
],
|
| 66 |
outputs= [
|
| 67 |
gr.Image(label="resp0"),
|
models.py
CHANGED
|
@@ -69,7 +69,8 @@ def make_image_controlnet(image: np.ndarray,
|
|
| 69 |
def make_inpainting(positive_prompt: str,
|
| 70 |
image: Image,
|
| 71 |
mask_image: np.ndarray,
|
| 72 |
-
negative_prompt: str = ""
|
|
|
|
| 73 |
"""Method to make inpainting
|
| 74 |
Args:
|
| 75 |
positive_prompt (str): positive prompt string
|
|
@@ -90,8 +91,8 @@ def make_inpainting(positive_prompt: str,
|
|
| 90 |
prompt=positive_prompt,
|
| 91 |
negative_prompt=negative_prompt,
|
| 92 |
num_inference_steps=50,
|
| 93 |
-
height=
|
| 94 |
-
width=
|
| 95 |
)
|
| 96 |
print("RESP !!!!",resp)
|
| 97 |
generated_image = resp.images[0]
|
|
|
|
| 69 |
def make_inpainting(positive_prompt: str,
|
| 70 |
image: Image,
|
| 71 |
mask_image: np.ndarray,
|
| 72 |
+
negative_prompt: str = "",
|
| 73 |
+
rezolution:int=512) -> List[Image.Image]:
|
| 74 |
"""Method to make inpainting
|
| 75 |
Args:
|
| 76 |
positive_prompt (str): positive prompt string
|
|
|
|
| 91 |
prompt=positive_prompt,
|
| 92 |
negative_prompt=negative_prompt,
|
| 93 |
num_inference_steps=50,
|
| 94 |
+
height=rezolution,
|
| 95 |
+
width=rezolution,
|
| 96 |
)
|
| 97 |
print("RESP !!!!",resp)
|
| 98 |
generated_image = resp.images[0]
|
preprocessing.py
CHANGED
|
@@ -6,7 +6,8 @@ import numpy as np
|
|
| 6 |
from PIL import Image, ImageFilter
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
# from enhance_config import ENHANCE_SETTINGS
|
| 11 |
|
| 12 |
LOGGING = logging.getLogger(__name__)
|
|
@@ -35,7 +36,7 @@ def preprocess_seg_mask(canvas_seg, real_seg: Image.Image = None) -> Tuple[np.nd
|
|
| 35 |
unique_colors = [color for color in unique_colors if np.sum(
|
| 36 |
np.all(image_seg == color, axis=-1)) > 100]
|
| 37 |
|
| 38 |
-
unique_colors_exact = [color for color in unique_colors if color in COLOR_RGB]
|
| 39 |
|
| 40 |
if real_seg is not None:
|
| 41 |
overlay_seg = np.array(real_seg)
|
|
@@ -74,9 +75,9 @@ def get_image() -> np.ndarray:
|
|
| 74 |
if 'initial_image' in st.session_state and st.session_state['initial_image'] is not None:
|
| 75 |
initial_image = st.session_state['initial_image']
|
| 76 |
if isinstance(initial_image, Image.Image):
|
| 77 |
-
return np.array(initial_image.resize((WIDTH, HEIGHT)))
|
| 78 |
else:
|
| 79 |
-
return np.array(Image.fromarray(initial_image).resize((WIDTH, HEIGHT)))
|
| 80 |
else:
|
| 81 |
return None
|
| 82 |
|
|
|
|
| 6 |
from PIL import Image, ImageFilter
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
+
import config
|
| 10 |
+
|
| 11 |
# from enhance_config import ENHANCE_SETTINGS
|
| 12 |
|
| 13 |
LOGGING = logging.getLogger(__name__)
|
|
|
|
| 36 |
unique_colors = [color for color in unique_colors if np.sum(
|
| 37 |
np.all(image_seg == color, axis=-1)) > 100]
|
| 38 |
|
| 39 |
+
unique_colors_exact = [color for color in unique_colors if color in config.COLOR_RGB]
|
| 40 |
|
| 41 |
if real_seg is not None:
|
| 42 |
overlay_seg = np.array(real_seg)
|
|
|
|
| 75 |
if 'initial_image' in st.session_state and st.session_state['initial_image'] is not None:
|
| 76 |
initial_image = st.session_state['initial_image']
|
| 77 |
if isinstance(initial_image, Image.Image):
|
| 78 |
+
return np.array(initial_image.resize((config.WIDTH, config.HEIGHT)))
|
| 79 |
else:
|
| 80 |
+
return np.array(Image.fromarray(initial_image).resize((config.WIDTH, config.HEIGHT)))
|
| 81 |
else:
|
| 82 |
return None
|
| 83 |
|