Spaces:
Sleeping
Sleeping
Commit
·
4f49a4d
1
Parent(s):
bb5fd6a
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
import requests
|
4 |
-
import io
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
img = Image.open(io.BytesIO(image.read()))
|
9 |
-
|
10 |
-
# Convert the image to base64 string
|
11 |
-
buffered = io.BytesIO()
|
12 |
-
img.save(buffered, format="PNG")
|
13 |
-
img_base64 = "data:image/png;base64," + buffered.getvalue().hex()
|
14 |
-
|
15 |
-
# Send a request to the endpoint with the image data
|
16 |
-
response = requests.get(
|
17 |
"https://4937ea62-c0b0-414f-afbc-53be1f5b0d06.id.repl.co/scan",
|
18 |
-
data={"base64":
|
19 |
)
|
|
|
20 |
|
21 |
-
# Process the response and return the result
|
22 |
-
if response.text == "sfw":
|
23 |
-
return "Safe for work"
|
24 |
-
elif response.text == "nsfw":
|
25 |
-
return "Not safe for work"
|
26 |
-
else:
|
27 |
-
return "Unknown"
|
28 |
-
|
29 |
-
# Create a Gradio interface
|
30 |
iface = gr.Interface(
|
31 |
-
fn=
|
32 |
-
inputs="
|
33 |
outputs="text",
|
34 |
title="AntiNSFW",
|
35 |
-
description="
|
36 |
)
|
37 |
|
38 |
-
# Launch the interface
|
39 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import requests
|
|
|
3 |
|
4 |
+
def anti_nsfw(image):
|
5 |
+
resp = requests.get(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
"https://4937ea62-c0b0-414f-afbc-53be1f5b0d06.id.repl.co/scan",
|
7 |
+
data={"base64": image}
|
8 |
)
|
9 |
+
return resp.text
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
iface = gr.Interface(
|
12 |
+
fn=anti_nsfw,
|
13 |
+
inputs="image",
|
14 |
outputs="text",
|
15 |
title="AntiNSFW",
|
16 |
+
description="Check if an image is safe for work (SFW) or not safe for work (NSFW)."
|
17 |
)
|
18 |
|
|
|
19 |
iface.launch()
|