nsfwalex commited on
Commit
271a7bc
Β·
verified Β·
1 Parent(s): 21b70df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -41
app.py CHANGED
@@ -1,9 +1,16 @@
1
- import gradio as gr
2
- import cv2
3
  import time
4
- from urllib.parse import parse_qs, urlparse
 
 
 
 
 
 
 
 
5
 
6
- TESTdevice = "cpu"
 
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 get_css(bg_color, width, height):
37
- return f"""
38
- body {{
39
- background-color: {bg_color};
40
- color: white;
41
- overflow: hidden; /* Prevent scrolling */
42
- }}
43
- .gradio-container {{
44
- background-color: {bg_color} !important;
45
- border: none !important;
46
- width: {width} !important; /* Set the width */
47
- height: {height} !important; /* Set the height */
48
- max-width: 100%; /* Ensure it does not exceed the container's width */
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
- def update_status(img):
56
- return inference(img), gr.update(value="Processing complete!")
 
 
57
 
58
- def create_interface(request: gr.Request):
59
- # Extract URL parameters
60
- query_params = request.query_params
61
- bg_color = query_params.get('bg_color', 'rgb(17, 24, 39)')
62
- width = int(query_params.get('width', 'auto'))
63
- height = int(query_params.get('height', '90%'))
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- css = get_css(bg_color, width, height)
 
66
 
67
- with gr.Blocks(css=css) as demo:
68
- with gr.Column():
69
- image_input = gr.Image(type="numpy", label="Upload Image", height=height, width=width)
70
- process_button = gr.Button("Process Image")
71
- status = gr.Markdown(value="")
72
 
73
- process_button.click(update_status, inputs=image_input, outputs=[image_input, status])
 
74
 
75
- return demo
76
 
77
- with gr.Blocks() as outer_demo:
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()