File size: 2,674 Bytes
60efdc5
d948530
 
 
c2eddce
60efdc5
c2eddce
 
b4d6bb3
 
 
 
c2eddce
b4d6bb3
 
c2eddce
 
 
 
 
 
 
 
 
fcaff26
92f472f
c4bf23b
fcaff26
92f472f
c2eddce
4da45b0
c4bf23b
4da45b0
60efdc5
c2eddce
d948530
 
 
 
 
 
 
 
 
 
f0978c5
 
d948530
 
f0978c5
d948530
 
 
 
 
 
c2eddce
f0978c5
 
 
 
 
c2eddce
f0978c5
 
 
 
 
 
 
 
 
509b60d
f0978c5
 
 
 
509b60d
d948530
509b60d
f0978c5
 
 
 
60efdc5
92f472f
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import gradio as gr
import cv2
import time
from urllib.parse import parse_qs, urlparse

TESTdevice = "cpu"
index = 1

def mainTest(inputpath, outpath):
    watermark = deep_nude_process(inputpath)
    watermark1 = cv2.cvtColor(watermark, cv2.COLOR_BGRA2RGBA)
    return watermark1

def deep_nude_process(inputpath):
    dress = cv2.imread(inputpath)
    h = dress.shape[0]
    w = dress.shape[1]
    dress = cv2.resize(dress, (512, 512), interpolation=cv2.INTER_CUBIC)
    watermark = process(dress)
    watermark = cv2.resize(watermark, (w, h), interpolation=cv2.INTER_CUBIC)
    return watermark

def inference(img):
    global index
    bgra = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
    inputpath = f"input_{index}.jpg"
    cv2.imwrite(inputpath, bgra)

    outputpath = f"out_{index}.jpg"
    index += 1
    print(time.strftime("START!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
    output = mainTest(inputpath, outputpath)
    print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
    return output

def get_css(bg_color, width, height):
    return f"""
    body {{
        background-color: {bg_color};
        color: white;
        overflow: hidden; /* Prevent scrolling */
    }}
    .gradio-container {{
        background-color: {bg_color} !important;
        border: none !important;
        width: {width}px !important;  /* Set the width */
        height: {height}px !important; /* Set the height */
        max-width: 100%; /* Ensure it does not exceed the container's width */
        max-height: 100%; /* Ensure it does not exceed the container's height */
        overflow: hidden; /* Prevent internal scrolling */
    }}
    footer {{display: none !important;}} /* Hide footer */
    """

def update_status(img):
    return inference(img), gr.update(value="Processing complete!")

def create_interface():
    # Default values
    bg_color = 'rgb(17, 24, 39)'
    width = 'auto'
    height = '100%'

    # Function to update the interface based on the URL parameters
    def update_interface(request: gr.Request):
        nonlocal bg_color, width, height
        query_params = parse_qs(urlparse(request.url).query)
        bg_color = query_params.get('bg_color', [bg_color])[0]
        width = int(query_params.get('width', [width])[0])
        height = int(query_params.get('height', [height])[0])
        css = get_css(bg_color, width, height)
        return gr.Blocks(css=css)

    with gr.Blocks() as demo:
        gr.Markdown("Loading...")  # Temporary placeholder
        
    demo.load(update_interface)

    return demo

demo = create_interface()

with gr.Blocks() as outer_demo:
    outer_demo.mount(demo)

demo.launch()