File size: 1,932 Bytes
372f297
13cb3ce
 
 
eff32bf
 
ff7142e
 
13cb3ce
 
 
 
 
 
 
 
 
 
eff32bf
405f281
 
 
 
f59e95f
28471f6
eff32bf
 
13cb3ce
eff32bf
 
f59e95f
bc435a1
 
 
28471f6
 
405f281
28471f6
bc435a1
405f281
13cb3ce
 
ff7142e
13cb3ce
405f281
 
 
 
13cb3ce
eff32bf
405f281
 
 
13cb3ce
 
 
405f281
 
 
 
 
 
 
 
 
 
13cb3ce
372f297
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
import io
from PIL import Image
import numpy as np

from config import WIDTH, HEIGHT
from models import make_image_controlnet, make_inpainting
from preprocessing import preprocess_seg_mask, get_image, get_mask

def image_to_byte_array(image: Image) -> bytes:
    # BytesIO is a fake file stored in memory
    imgByteArr = io.BytesIO()
    # image.save expects a file as a argument, passing a bytes io ins
    image.save(imgByteArr, format='png')  # image.format
    # Turn the BytesIO object back into a bytes object
    imgByteArr = imgByteArr.getvalue()
    return imgByteArr

def predict(input_img1,
            input_img2,
            positive_prompt,
            negative_prompt
            ):

    print("predict")
    input_img1 = Image.fromarray(input_img1)
    input_img2 = Image.fromarray(input_img2)

    input_img1 = input_img1.resize((WIDTH, HEIGHT))
    input_img2 = input_img2.resize((WIDTH, WIDTH))

    canvas_mask = np.array(input_img2)
    mask = get_mask(canvas_mask)

    print(input_img1, mask)

    result_image = make_inpainting(positive_prompt=positive_prompt,
                                   image=input_img1,
                                   mask_image=mask,
                                   negative_prompt=negative_prompt,
                                   )

    return result_image

def test1(param1):
    return  "here !"

gr.Interface(
    predict,
    inputs=[gr.Image(label="img", sources=['upload', 'webcam'], type="numpy"),
            gr.Image(label="mask", sources=['upload', 'webcam'], type="numpy"),
            gr.Textbox(label="positive_prompt"),
            gr.Textbox(label="negative_prompt")
            ],
    outputs= gr.Image(label="resp"),
    title="rem fur 1",
).launch(share=True)
#
#
# gr.Interface(
#     test1,
#     inputs=[gr.Textbox(label="param1")],
#     outputs= gr.Textbox(label="result"),
#     title="rem fur 1",
# ).launch(share=True)