-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from PIL import Image | ||
import imagehash | ||
import requests | ||
from io import BytesIO | ||
|
||
def imagehashed(url: str): | ||
response = requests.get(url) | ||
buffer = response.content | ||
|
||
im = Image.open(BytesIO(buffer)) | ||
avg_hash = imagehash.average_hash(im) | ||
|
||
return { "hash": str(avg_hash)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.api.routes import upscale, nsfw_detector | ||
from app.api.routes import upscale, nsfw_detector, hashes | ||
|
||
router = APIRouter() | ||
router.include_router(upscale.router, tags=["upscaler"], prefix="/upscales") | ||
router.include_router(nsfw_detector.router, tags=["detector"], prefix="/detects") | ||
router.include_router(hashes.router, tags=["hash"], prefix="/hash") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from fastapi import APIRouter, HTTPException, FastAPI | ||
from app.api.handlers.imagehash import imagehashed | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
from starlette.responses import JSONResponse | ||
|
||
|
||
class Image(BaseModel): | ||
url: str | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
# post because I don't want to deal with url | ||
@router.post("/") | ||
def hashes(image: Image): | ||
result = imagehashed(image.url) | ||
if result is None: | ||
raise HTTPException(status_code=400, detail="url not found") | ||
return JSONResponse(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ python-magic | |
requests | ||
tensorflow | ||
tensorflow-hub | ||
imagehash |