Utkarsh-Singh commited on
Commit
8afee43
·
verified ·
1 Parent(s): 2d4b74e

changes model

Browse files
Files changed (1) hide show
  1. main.py +11 -11
main.py CHANGED
@@ -1,16 +1,16 @@
1
  from fastapi import FastAPI,UploadFile,File,HTTPException
2
  from transformers import pipeline
3
- from facenet_pytorch import MTCNN
4
  from PIL import Image
5
  import io
6
 
7
  app=FastAPI(title="Deepfake")
8
 
9
- print("Face Detector Loading...")
10
- mtcnn=MTCNN(keep_all=False,device='cpu')
11
 
12
  print("Deepfake AI Loading...")
13
- pipe=pipeline("image-classification",model="dima806/deepfake_vs_real_image_detection")
14
  print("All Systems Loaded!")
15
 
16
  @app.post("/api/v1/predict/image")
@@ -22,13 +22,13 @@ async def predict_image(file:UploadFile=File(...)):
22
  image_bytes=await file.read()
23
  image=Image.open(io.BytesIO(image_bytes)).convert("RGB")
24
  # check for human faces
25
- boxes, _ =mtcnn.detect(image)
26
 
27
- if boxes is None:
28
- return {
29
- "status":"failed",
30
- "message":"No human face detected in the image. Please upload a clear human portrait."
31
- }
32
 
33
  results=pipe(image)
34
  formatted_results={res['label'].lower(): round(res['score'] * 100, 2) for res in results}
@@ -36,7 +36,7 @@ async def predict_image(file:UploadFile=File(...)):
36
 
37
  return {
38
  "status":"success 200",
39
- "faces_detected":len(boxes),
40
  "verdict":verdict,
41
  "confidence":formatted_results[verdict]
42
  }
 
1
  from fastapi import FastAPI,UploadFile,File,HTTPException
2
  from transformers import pipeline
3
+ # from facenet_pytorch import MTCNN
4
  from PIL import Image
5
  import io
6
 
7
  app=FastAPI(title="Deepfake")
8
 
9
+ # print("Face Detector Loading...")
10
+ # mtcnn=MTCNN(keep_all=False,device='cpu')
11
 
12
  print("Deepfake AI Loading...")
13
+ pipe=pipeline("image-classification",model="haywoodsloan/ai-image-detector-dev-deploy")
14
  print("All Systems Loaded!")
15
 
16
  @app.post("/api/v1/predict/image")
 
22
  image_bytes=await file.read()
23
  image=Image.open(io.BytesIO(image_bytes)).convert("RGB")
24
  # check for human faces
25
+ # boxes, _ =mtcnn.detect(image)
26
 
27
+ # if boxes is None:
28
+ # return {
29
+ # "status":"failed",
30
+ # "message":"No human face detected in the image. Please upload a clear human portrait."
31
+ # }
32
 
33
  results=pipe(image)
34
  formatted_results={res['label'].lower(): round(res['score'] * 100, 2) for res in results}
 
36
 
37
  return {
38
  "status":"success 200",
39
+ # "faces_detected":len(boxes),
40
  "verdict":verdict,
41
  "confidence":formatted_results[verdict]
42
  }