Spaces:
Running
Running
Dan Bochman
commited on
Commit
•
206a0d8
1
Parent(s):
2e67f30
reverted NSFW IP blacklisting; doesn't seem to work as expected on HF
Browse files
app.py
CHANGED
@@ -94,16 +94,10 @@ def parse_checkboxes(checkboxes):
|
|
94 |
# ----------------- CORE FUNCTION ----------------- #
|
95 |
|
96 |
CATEGORY_API_MAPPING = {"Top": "tops", "Bottom": "bottoms", "Full-body": "one-pieces"}
|
97 |
-
NSFW_ATTEMPTS = {}
|
98 |
|
99 |
|
100 |
-
async def get_tryon_result(model_image, garment_image, category, checkboxes
|
101 |
logger.info("Starting new try-on request...")
|
102 |
-
client_ip = request.client.host
|
103 |
-
|
104 |
-
if NSFW_ATTEMPTS.get(client_ip, 0) >= 3:
|
105 |
-
logger.info(f"Blocking request from blacklisted IP: {client_ip}")
|
106 |
-
return NSFW
|
107 |
|
108 |
# preprocessing: convert to RGB, resize, encode to base64
|
109 |
model_image, garment_image = map(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2BGR), [model_image, garment_image])
|
@@ -149,8 +143,6 @@ async def get_tryon_result(model_image, garment_image, category, checkboxes, req
|
|
149 |
error_msg = f"Prediction failed: {error}"
|
150 |
logger.error(error_msg)
|
151 |
if "NSFW" in error:
|
152 |
-
logger.info(f"NSFW attempt IP address: {client_ip}")
|
153 |
-
NSFW_ATTEMPTS[client_ip] = NSFW_ATTEMPTS.get(client_ip, 0) + 1
|
154 |
return NSFW
|
155 |
raise Exception(error_msg)
|
156 |
|
@@ -228,4 +220,5 @@ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Monochrome(radius_size=sizes.radi
|
|
228 |
if __name__ == "__main__":
|
229 |
ip = requests.get("http://ifconfig.me/ip", timeout=1).text.strip()
|
230 |
logger.info(f"VM IP address: {ip}")
|
231 |
-
demo.
|
|
|
|
94 |
# ----------------- CORE FUNCTION ----------------- #
|
95 |
|
96 |
CATEGORY_API_MAPPING = {"Top": "tops", "Bottom": "bottoms", "Full-body": "one-pieces"}
|
|
|
97 |
|
98 |
|
99 |
+
async def get_tryon_result(model_image, garment_image, category, checkboxes):
|
100 |
logger.info("Starting new try-on request...")
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
# preprocessing: convert to RGB, resize, encode to base64
|
103 |
model_image, garment_image = map(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2BGR), [model_image, garment_image])
|
|
|
143 |
error_msg = f"Prediction failed: {error}"
|
144 |
logger.error(error_msg)
|
145 |
if "NSFW" in error:
|
|
|
|
|
146 |
return NSFW
|
147 |
raise Exception(error_msg)
|
148 |
|
|
|
220 |
if __name__ == "__main__":
|
221 |
ip = requests.get("http://ifconfig.me/ip", timeout=1).text.strip()
|
222 |
logger.info(f"VM IP address: {ip}")
|
223 |
+
demo.queue(default_concurrency_limit=3)
|
224 |
+
demo.launch(share=False)
|