mirror of
https://github.com/steelcityamir/safe-content-ai.git
synced 2024-08-16 22:00:31 +03:00
Updates
This commit is contained in:
parent
bdfad8aa2f
commit
199e2fad90
4
main.py
4
main.py
@ -44,8 +44,8 @@ async def classify_image(file: UploadFile = File(...)):
|
|||||||
|
|
||||||
# Prepare the custom response data
|
# Prepare the custom response data
|
||||||
response_data = {
|
response_data = {
|
||||||
"filename": file.filename,
|
"file_name": file.filename,
|
||||||
"isNsfw": best_prediction['label'] == 'nsfw',
|
"is_nsfw": best_prediction['label'] == 'nsfw',
|
||||||
"confidence_percentage": confidence_percentage
|
"confidence_percentage": confidence_percentage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
sunflower.jpg
Normal file
BIN
sunflower.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 135 KiB |
3
test-requirements.txt
Normal file
3
test-requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fastapi==0.110.2
|
||||||
|
httpx==0.27.0
|
||||||
|
pytest==8.1.1
|
16
test_main.py
Normal file
16
test_main.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from main import app
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
|
||||||
|
file_name = "sunflower.jpg"
|
||||||
|
|
||||||
|
def test_read_main():
|
||||||
|
response = client.post("/api/v1/detect", files={"file": (file_name, open(file_name, "rb"), "image/jpeg")})
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"file_name": file_name, "is_nsfw": False, "confidence_percentage": 100.0}
|
||||||
|
|
||||||
|
def test_invalid_input():
|
||||||
|
response = client.post("/api/v1/detect", files={})
|
||||||
|
assert response.status_code == 422
|
||||||
|
|
Loading…
Reference in New Issue
Block a user