Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,11 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from
|
3 |
-
from PIL import Image
|
4 |
-
import requests
|
5 |
-
from io import BytesIO
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
"""
|
15 |
-
Analisa uma imagem a partir de um URL e detecta conteúdo NSFW.
|
16 |
-
"""
|
17 |
-
try:
|
18 |
-
# Baixar a imagem a partir da URL
|
19 |
-
response = requests.get(image_url)
|
20 |
-
response.raise_for_status() # Lança erro se a URL for inválida
|
21 |
-
image = Image.open(BytesIO(response.content))
|
22 |
-
|
23 |
-
# Fazer a predição
|
24 |
-
predictions = predict.classify(model, {"image": image})
|
25 |
-
|
26 |
-
# Resultados
|
27 |
-
nsfw_score = predictions["image"]["porn"] + predictions["image"]["sexy"]
|
28 |
-
sfw_score = predictions["image"]["neutral"]
|
29 |
-
classification = "NSFW" if nsfw_score > sfw_score else "SFW"
|
30 |
-
|
31 |
-
return {
|
32 |
-
"image_url": image_url,
|
33 |
-
"classification": classification,
|
34 |
-
"scores": predictions["image"]
|
35 |
-
}
|
36 |
-
except Exception as e:
|
37 |
-
return {"error": str(e)}
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from routers import profanity # Importa a rota de palavrões
|
|
|
|
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
@app.get("/")
|
7 |
+
def greet_json():
|
8 |
+
return {"Hello": "World!"}
|
9 |
|
10 |
+
# Inclui as rotas de profanity
|
11 |
+
app.include_router(profanity.router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|