Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ import sys
|
|
7 |
from PIL import Image
|
8 |
import torch
|
9 |
import gradio as gr
|
10 |
-
import urllib.parse
|
11 |
|
12 |
TESTdevice = "cpu"
|
13 |
index = 1
|
@@ -38,56 +37,49 @@ def inference(img):
|
|
38 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
39 |
return output
|
40 |
|
41 |
-
def
|
42 |
-
|
43 |
-
parsed_url = urllib.parse.urlparse(url)
|
44 |
-
params = urllib.parse.parse_qs(parsed_url.query)
|
45 |
-
|
46 |
-
width = params.get('width', ['auto'])[0]
|
47 |
-
height = params.get('height', ['100%'])[0]
|
48 |
-
bg_color = params.get('bg_color', ['rgb(17, 24, 39)'])[0]
|
49 |
-
|
50 |
-
return width, height, bg_color
|
51 |
-
|
52 |
-
title = "Undress AI"
|
53 |
-
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 β"
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
css
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
}}
|
66 |
-
.gradio-container {{
|
67 |
-
background-color: {bg_color} !important;
|
68 |
-
border: none !important;
|
69 |
-
width: {width} !important;
|
70 |
-
height: {height} !important;
|
71 |
-
max-width: 100%;
|
72 |
-
max-height: 100%;
|
73 |
-
overflow: hidden;
|
74 |
-
}}
|
75 |
-
footer {{
|
76 |
-
display: none !important;
|
77 |
-
}}
|
78 |
-
"""
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
with gr.Blocks(css=formatted_css) as demo:
|
84 |
-
with gr.Column():
|
85 |
-
image_input = gr.Image(type="numpy", label="Upload Image", height=512, width=512)
|
86 |
-
process_button = gr.Button("Process Image")
|
87 |
-
|
88 |
-
def update_status(img):
|
89 |
-
return inference(img), gr.update(value="Processing complete!")
|
90 |
|
91 |
-
|
|
|
92 |
|
93 |
-
|
|
|
7 |
from PIL import Image
|
8 |
import torch
|
9 |
import gradio as gr
|
|
|
10 |
|
11 |
TESTdevice = "cpu"
|
12 |
index = 1
|
|
|
37 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
38 |
return output
|
39 |
|
40 |
+
def update_status(img):
|
41 |
+
return inference(img), gr.update(value="Processing complete!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
def init_interface(request: gr.Request):
|
44 |
+
query_params = request.query_params
|
45 |
+
bg_color = query_params.get('bg_color', 'rgb(17, 24, 39)')
|
46 |
+
image_height = query_params.get('image_height', '90%')
|
47 |
+
css = f"""
|
48 |
+
body {{
|
49 |
+
background-color: {bg_color};
|
50 |
+
color: white;
|
51 |
+
overflow: hidden;
|
52 |
+
}}
|
53 |
+
.gradio-container {{
|
54 |
+
background-color: {bg_color} !important;
|
55 |
+
border: none !important;
|
56 |
+
}}
|
57 |
+
.image-container {{
|
58 |
+
height: {image_height} !important;
|
59 |
+
display: flex;
|
60 |
+
align-items: center;
|
61 |
+
justify-content: center;
|
62 |
+
}}
|
63 |
+
.image-container img {{
|
64 |
+
width: auto !important;
|
65 |
+
height: 100% !important;
|
66 |
+
}}
|
67 |
+
footer {{
|
68 |
+
display: none !important;
|
69 |
+
}}
|
70 |
+
"""
|
71 |
|
72 |
+
with gr.Blocks(css=css) as demo:
|
73 |
+
with gr.Column():
|
74 |
+
with gr.Row(elem_id="image-container"):
|
75 |
+
image_input = gr.Image(type="numpy", label="Upload Image")
|
76 |
+
process_button = gr.Button("Process Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
process_button.click(update_status, inputs=image_input, outputs=[image_input])
|
79 |
+
|
80 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
with gr.Blocks() as outer_demo:
|
83 |
+
outer_demo.load(init_interface)
|
84 |
|
85 |
+
outer_demo.launch()
|