Spaces:
Sleeping
Sleeping
Commit
·
e68b3a3
1
Parent(s):
e48d789
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import base64
|
|
|
|
| 4 |
|
| 5 |
def image_to_base64(image):
|
| 6 |
with open(image.name, "rb") as file:
|
|
@@ -8,6 +9,12 @@ def image_to_base64(image):
|
|
| 8 |
return encoded_string.decode("utf-8")
|
| 9 |
|
| 10 |
def anti_nsfw(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
encoded_image = image_to_base64(image)
|
| 12 |
resp = requests.get(
|
| 13 |
"https://4937ea62-c0b0-414f-afbc-53be1f5b0d06.id.repl.co/scan",
|
|
@@ -17,7 +24,7 @@ def anti_nsfw(image):
|
|
| 17 |
|
| 18 |
iface = gr.Interface(
|
| 19 |
fn=anti_nsfw,
|
| 20 |
-
inputs=
|
| 21 |
outputs="text",
|
| 22 |
title="AntiNSFW",
|
| 23 |
description="Check if an image is safe for work (SFW) or not safe for work (NSFW)."
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import base64
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
def image_to_base64(image):
|
| 7 |
with open(image.name, "rb") as file:
|
|
|
|
| 9 |
return encoded_string.decode("utf-8")
|
| 10 |
|
| 11 |
def anti_nsfw(image):
|
| 12 |
+
allowed_extensions = [".png", ".jpeg", ".jpg"]
|
| 13 |
+
file_extension = os.path.splitext(image.name)[1].lower()
|
| 14 |
+
|
| 15 |
+
if file_extension not in allowed_extensions:
|
| 16 |
+
return "Invalid file type. Please upload a PNG or JPEG image."
|
| 17 |
+
|
| 18 |
encoded_image = image_to_base64(image)
|
| 19 |
resp = requests.get(
|
| 20 |
"https://4937ea62-c0b0-414f-afbc-53be1f5b0d06.id.repl.co/scan",
|
|
|
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=anti_nsfw,
|
| 27 |
+
inputs="file",
|
| 28 |
outputs="text",
|
| 29 |
title="AntiNSFW",
|
| 30 |
description="Check if an image is safe for work (SFW) or not safe for work (NSFW)."
|