Spaces:
Sleeping
Sleeping
File size: 938 Bytes
3b72630 64301f6 e68b3a3 64301f6 4cb0029 3b72630 de18720 e68b3a3 4cb0029 d331efd 95232b0 47d9e1a 3b72630 4f49a4d 3b72630 4f49a4d e68b3a3 3b72630 4f49a4d 3b72630 de18720 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
import requests
import base64
import os
def image_to_base64(image):
with open(image.name, "rb") as file:
encoded_string = base64.b64encode(file.read())
return encoded_string.decode("utf-8")
def anti_nsfw(image):
allowed_extensions = [".png", ".jpeg", ".jpg"]
file_extension = os.path.splitext(image.name)[1].lower()
if file_extension not in allowed_extensions:
return "Invalid file type. Please upload a PNG or JPEG image."
encoded_image = image_to_base64(image)
resp = requests.post(
"https://8d2e08d2-7720-461c-8281-4ad7f69557e7.id.repl.co/scan",
data={"base64": f"data:image/png;base64,{encoded_image}"}
)
return resp.text
iface = gr.Interface(
fn=anti_nsfw,
inputs="file",
outputs="text",
title="AntiNSFW",
description="Check if an image is safe for work (SFW) or not safe for work (NSFW)."
)
iface.launch()
|