Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,16 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import cv2
|
3 |
import time
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
|
|
7 |
index = 1
|
8 |
|
9 |
def mainTest(inputpath, outpath):
|
@@ -25,7 +32,6 @@ def inference(img):
|
|
25 |
bgra = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
|
26 |
inputpath = f"input_{index}.jpg"
|
27 |
cv2.imwrite(inputpath, bgra)
|
28 |
-
|
29 |
outputpath = f"out_{index}.jpg"
|
30 |
index += 1
|
31 |
print(time.strftime("START!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
@@ -33,46 +39,56 @@ def inference(img):
|
|
33 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
34 |
return output
|
35 |
|
36 |
-
def
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
.
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
max-height: 100%; /* Ensure it does not exceed the container's height */
|
50 |
-
overflow: hidden; /* Prevent internal scrolling */
|
51 |
-
}}
|
52 |
-
footer {{display: none !important;}} /* Hide footer */
|
53 |
-
"""
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
status = gr.Markdown(value="")
|
72 |
|
73 |
-
|
|
|
74 |
|
75 |
-
|
76 |
|
77 |
-
|
78 |
-
gr.Interface(fn=create_interface).launch()
|
|
|
|
|
|
|
1 |
import time
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
import argparse
|
5 |
+
import cv2
|
6 |
+
import sys
|
7 |
+
from PIL import Image
|
8 |
+
import torch
|
9 |
+
import gradio as gr
|
10 |
+
import urllib.parse
|
11 |
|
12 |
+
TEST
|
13 |
+
device = "cpu"
|
14 |
index = 1
|
15 |
|
16 |
def mainTest(inputpath, outpath):
|
|
|
32 |
bgra = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
|
33 |
inputpath = f"input_{index}.jpg"
|
34 |
cv2.imwrite(inputpath, bgra)
|
|
|
35 |
outputpath = f"out_{index}.jpg"
|
36 |
index += 1
|
37 |
print(time.strftime("START!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
|
|
39 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
40 |
return output
|
41 |
|
42 |
+
def parse_url_params():
|
43 |
+
url = os.environ.get('GRADIO_SERVER_URL', '')
|
44 |
+
parsed_url = urllib.parse.urlparse(url)
|
45 |
+
params = urllib.parse.parse_qs(parsed_url.query)
|
46 |
+
|
47 |
+
width = params.get('width', ['auto'])[0]
|
48 |
+
height = params.get('height', ['100%'])[0]
|
49 |
+
bg_color = params.get('bg_color', ['rgb(17, 24, 39)'])[0]
|
50 |
+
|
51 |
+
return width, height, bg_color
|
52 |
+
|
53 |
+
title = "Undress AI"
|
54 |
+
description = "β Input photos of people, similar to the test picture at the bottom, and undress pictures will be produced. You may have to wait 30 seconds for a picture. π Do not upload personal photos π There is a queue system. According to the logic of first come, first served, only one picture will be made at a time. Must be able to at least see the outline of a human body β"
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
examples = [
|
57 |
+
['input.png', 'Test'],
|
58 |
+
['input.jpg', 'Test'],
|
59 |
+
]
|
60 |
|
61 |
+
css = """
|
62 |
+
body {{
|
63 |
+
background-color: {bg_color};
|
64 |
+
color: white;
|
65 |
+
overflow: hidden;
|
66 |
+
}}
|
67 |
+
.gradio-container {{
|
68 |
+
background-color: {bg_color} !important;
|
69 |
+
border: none !important;
|
70 |
+
width: {width} !important;
|
71 |
+
height: {height} !important;
|
72 |
+
max-width: 100%;
|
73 |
+
max-height: 100%;
|
74 |
+
overflow: hidden;
|
75 |
+
}}
|
76 |
+
footer {{
|
77 |
+
display: none !important;
|
78 |
+
}}
|
79 |
+
"""
|
80 |
|
81 |
+
width, height, bg_color = parse_url_params()
|
82 |
+
formatted_css = css.format(width=width, height=height, bg_color=bg_color)
|
83 |
|
84 |
+
with gr.Blocks(css=formatted_css) as demo:
|
85 |
+
with gr.Column():
|
86 |
+
image_input = gr.Image(type="numpy", label="Upload Image", height=512, width=512)
|
87 |
+
process_button = gr.Button("Process Image")
|
|
|
88 |
|
89 |
+
def update_status(img):
|
90 |
+
return inference(img), gr.update(value="Processing complete!")
|
91 |
|
92 |
+
process_button.click(update_status, inputs=image_input, outputs=[image_input])
|
93 |
|
94 |
+
demo.launch()
|
|