Skip to content

Commit

Permalink
add anti-nsfw
Browse files Browse the repository at this point in the history
  • Loading branch information
Qewertyy committed Dec 30, 2023
1 parent 190476f commit 8602870
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/antinsfw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from lexica import Client

def main(image_url: str) -> dict:
client = Client()
response = client.AntiNsfw(image_url)
if response['content']['sfw'] == True:
return "This image is safe for work."
else:
return "This image is not safe for work."

if __name__ == "__main__":
print(main("https://graph.org/file/13e95c6cc932530823391.png"))
14 changes: 14 additions & 0 deletions examples/async_antinsfw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from lexica import AsyncClient
import asyncio

async def main(image_url: str) -> dict:
client = AsyncClient()
response = await client.AntiNsfw(image_url)
await client.close()
if response['content']['sfw'] == True:
return "This image is safe for work."
else:
return "This image is not safe for work."

if __name__ == "__main__":
print(asyncio.run(main("https://graph.org/file/13e95c6cc932530823391.png")))
28 changes: 28 additions & 0 deletions lexica/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,32 @@ def SearchImages(self,query: str, page: int=0,engine: str="google") -> dict:
method='POST',
params={"query": query}
)
return resp

def AntiNsfw(self, imageUrl: str) -> dict:
"""
Check for an image if it is safe for work or not
Example:
>>> client = Client()
>>> response = client.AntiNsfw(imageUrl)
>>> print(response)
Args:
imageUrl (str): url of the image for reverse search.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": {
"sfw": bool #true if sfw (safe for work) else false
},
"code": int
}
"""
resp = self._request(
url=f'{self.url}/anti-nsfw',
method='POST',
params={"img_url": imageUrl}
)
return resp
28 changes: 28 additions & 0 deletions lexica/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,32 @@ async def SearchImages(self,query: str, page: int=0,engine: str="google") -> dic
method='POST',
params={'query': query,'page':page}
)
return resp

async def AntiNsfw(self, imageUrl: str) -> dict:
"""
Check for an image if it is safe for work or not
Example:
>>> client = AsyncClient()
>>> response = await client.AntiNsfw(imageUrl)
>>> print(response)
Args:
imageUrl (str): url of the image for anti nsfw.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": {
"sfw": bool #true if sfw (safe for work) else false
},
"code": int
}
"""
resp = await self._request(
url=f'{self.url}/anti-nsfw',
method='POST',
params={'img_url': imageUrl}
)
return resp
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_long_description():

setup(
name="lexica-api",
version="1.5.0",
version="1.5.1",
author="Qewertyy",
author_email="[email protected]",
description="The python package for api.qewertyy.me",
Expand Down

0 comments on commit 8602870

Please sign in to comment.