|
import time |
|
import subprocess |
|
import os |
|
import argparse |
|
import cv2 |
|
import sys |
|
from PIL import Image |
|
import torch |
|
import gradio as gr |
|
|
|
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 update_status(img): |
|
return inference(img), gr.update(value="Processing complete!") |
|
|
|
def init_interface(request: gr.Request): |
|
query_params = request.query_params |
|
bg_color = query_params.get('bg_color', 'rgb(17, 24, 39)') |
|
image_height = query_params.get('image_height', '90%') |
|
css = f""" |
|
body {{ |
|
background-color: {bg_color}; |
|
color: white; |
|
overflow: hidden; |
|
}} |
|
.gradio-container {{ |
|
background-color: {bg_color} !important; |
|
border: none !important; |
|
}} |
|
.image-container {{ |
|
height: {image_height} !important; |
|
display: flex; |
|
align-items: center; |
|
justify-content: center; |
|
}} |
|
.image-container img {{ |
|
width: auto !important; |
|
height: 100% !important; |
|
}} |
|
footer {{ |
|
display: none !important; |
|
}} |
|
""" |
|
|
|
with gr.Blocks(css=css) as demo: |
|
with gr.Column(): |
|
with gr.Row(elem_id="image-container"): |
|
image_input = gr.Image(type="numpy", label="Upload Image") |
|
process_button = gr.Button("Process Image") |
|
|
|
process_button.click(update_status, inputs=image_input, outputs=[image_input]) |
|
|
|
return demo |
|
|
|
with gr.Blocks() as outer_demo: |
|
outer_demo.load(init_interface) |
|
|
|
outer_demo.launch() |
|
|