Spaces:
Sleeping
Sleeping
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from run import process
|
| 2 |
+
import time
|
| 3 |
+
import subprocess
|
| 4 |
+
import os
|
| 5 |
+
import argparse
|
| 6 |
+
import cv2
|
| 7 |
+
import sys
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import torch
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
TESTdevice = "cpu"
|
| 14 |
+
|
| 15 |
+
index = 1
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
main.py
|
| 20 |
+
|
| 21 |
+
How to run:
|
| 22 |
+
python main.py
|
| 23 |
+
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def mainTest(inputpath, outpath):
|
| 28 |
+
watermark = deep_nude_process(inputpath)
|
| 29 |
+
cv2.imwrite(outpath, watermark)
|
| 30 |
+
return watermark
|
| 31 |
+
#
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def deep_nude_process(item):
|
| 35 |
+
# print('Processing {}'.format(item))
|
| 36 |
+
# dress = cv2.imread(item)
|
| 37 |
+
dress = (item)
|
| 38 |
+
h = dress.shape[0]
|
| 39 |
+
w = dress.shape[1]
|
| 40 |
+
dress = cv2.resize(dress, (512, 512), interpolation=cv2.INTER_CUBIC)
|
| 41 |
+
watermark = process(dress)
|
| 42 |
+
watermark = cv2.resize(watermark, (w, h), interpolation=cv2.INTER_CUBIC)
|
| 43 |
+
return watermark
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def inference(img):
|
| 47 |
+
global index
|
| 48 |
+
# inputpath = "input/" + str(index) + ".jpg"
|
| 49 |
+
outputpath = "out_" + str(index) + ".jpg"
|
| 50 |
+
# cv2.imwrite(inputpath, img)
|
| 51 |
+
index += 1
|
| 52 |
+
print(time.strftime("START!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
| 53 |
+
output = mainTest(img, outputpath)
|
| 54 |
+
print(time.strftime("FINISH!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
| 55 |
+
return output
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
title = "AI脱衣"
|
| 59 |
+
description = "传入人物照片,类似最下方测试图的那种,将制作脱衣图,一张图至少等40秒,别传私人照片,禁止传真人照片"
|
| 60 |
+
|
| 61 |
+
examples = [
|
| 62 |
+
['input.png', '测试图'],
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
web = gr.Interface(inference,
|
| 67 |
+
inputs="image",
|
| 68 |
+
outputs="image",
|
| 69 |
+
title=title,
|
| 70 |
+
description=description,
|
| 71 |
+
examples=examples,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
if __name__ == '__main__':
|
| 75 |
+
web.launch(
|
| 76 |
+
share=True,
|
| 77 |
+
enable_queue=True
|
| 78 |
+
)
|