ImagineAI-Real commited on
Commit
64301f6
·
1 Parent(s): 4f49a4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,16 +1,23 @@
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)."
 
1
  import gradio as gr
2
  import requests
3
+ import base64
4
+
5
+ def encode_image(image_path):
6
+ with open(image_path, "rb") as image_file:
7
+ encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
8
+ return encoded_string
9
 
10
  def anti_nsfw(image):
11
+ encoded_image = encode_image(image.name)
12
  resp = requests.get(
13
  "https://4937ea62-c0b0-414f-afbc-53be1f5b0d06.id.repl.co/scan",
14
+ data={"base64": f"data:image/png;base64,{encoded_image}"}
15
  )
16
  return resp.text
17
 
18
  iface = gr.Interface(
19
  fn=anti_nsfw,
20
+ inputs="file",
21
  outputs="text",
22
  title="AntiNSFW",
23
  description="Check if an image is safe for work (SFW) or not safe for work (NSFW)."