habulaj commited on
Commit
3a62be7
·
1 Parent(s): cbc0798

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -33
app.py CHANGED
@@ -1,37 +1,11 @@
1
- from fastapi import FastAPI, Query
2
- from nsfw_detector import predict
3
- from PIL import Image
4
- import requests
5
- from io import BytesIO
6
 
7
  app = FastAPI()
8
 
9
- # Carregar o modelo pré-treinado
10
- model = predict.load_model("nsfw_mobilenet2.224x224.h5") # Baixe o modelo ao configurar
 
11
 
12
- @app.get("/check-nsfw/")
13
- def check_nsfw(image_url: str = Query(..., description="URL da imagem para análise")):
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)