MAS-AI-0000 commited on
Commit
abd4928
·
verified ·
1 Parent(s): 707b788

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -47,29 +47,30 @@ async def predict(image: UploadFile = File(...)):
47
 
48
  image_data = await image.read()
49
  pil_img = Image.open(io.BytesIO(image_data)).convert("RGB")
50
- profile_img = profile_image_for_cnn_predict(pil_img, crop_size=512)
51
- if isinstance(profile_img, str):
52
- return (f"Error processing image: {profile_img}")
 
 
 
 
53
  else:
54
- print(f"Profile image shape: {profile_img.shape}")
55
- cnnPred = CNNPredict(profile_img)
56
- resnetPred = ResnetPredict(profile_img)
57
- clipPred = clip_predict(pil_img, crop_size=512)
58
- #print(f"CNN Prediction (Real prob): {cnnPred:.4f}")
59
- #print(f"ResNet Prediction (Real prob): {resnetPred:.4f}")
60
- #print(f"CLIP Prediction (AI prob): {clipPred:.4f}")
61
- resnet_class = 1 if resnetPred >= 0.5 else 0
62
  cnn_class = 1 if cnnPred >= 0.5 else 0
63
- clip_class = 0 if clipPred > 0.5 else 1
64
- resnet_conf = resnetPred if resnetPred >= 0.5 else 1 - resnetPred
65
  cnn_conf = cnnPred if cnnPred >= 0.5 else 1 - cnnPred
66
- clip_conf = clipPred if clipPred > 0.5 else 1 - clipPred
67
- #Predicted classes 1 is Real, 0 is AI
68
- predictions = [
69
- PredictionEntry(model="CNN", predicted_class=cnn_class, confidence=round(float(cnn_conf), 4)),
70
- PredictionEntry(model="ResNet", predicted_class=resnet_class, confidence=round(float(resnet_conf), 4)),
71
- PredictionEntry(model="CLIP", predicted_class=clip_class, confidence=round(float(clip_conf), 4)),
72
- ]
 
 
 
 
 
 
 
73
  return ImagePredictionResponse(predictions=predictions)
74
 
75
  @app.post(
 
47
 
48
  image_data = await image.read()
49
  pil_img = Image.open(io.BytesIO(image_data)).convert("RGB")
50
+
51
+ predictions=[]
52
+ cnnPred = CNNPredict(pil_img)
53
+ if isinstance(cnnPred, str):
54
+ # An error occurred during CNN prediction
55
+ print("CNN preprocessing error:", cnnPred)
56
+ predictions.append(PredictionEntry(model="CNN", error=cnnPred, predicted_class=-1, confidence=0.0))
57
  else:
 
 
 
 
 
 
 
 
58
  cnn_class = 1 if cnnPred >= 0.5 else 0
 
 
59
  cnn_conf = cnnPred if cnnPred >= 0.5 else 1 - cnnPred
60
+ predictions.append( PredictionEntry(model="CNN", predicted_class=cnn_class, confidence=round(float(cnn_conf), 4)))
61
+ clipPred = CLIPPredict(pil_img)
62
+ if isinstance(clipPred, str):
63
+ # An error occurred during CLIP prediction
64
+ print("CLIP error:", clipPred)
65
+ predictions.append(PredictionEntry(model="CLIP", error=clipPred, predicted_class=-1, confidence=0.0))
66
+ else:
67
+ clip_class = 1 if clipPred > 0.5 else 0
68
+ clip_conf = clipPred if clipPred >= 0.5 else 1 - clipPred
69
+ predictions.append( PredictionEntry(model="CLIP", predicted_class=clip_class, confidence=round(float(clip_conf), 4)))
70
+ #print(f"CNN Prediction (AI prob): {cnnPred:.4f}")
71
+ #print(f"ResNet Prediction (AI prob): {resnetPred:.4f}")
72
+ #print(f"CLIP Prediction (AI prob): {clipPred:.4f}")
73
+ #Predicted classes 1 is Real, 0 is AI
74
  return ImagePredictionResponse(predictions=predictions)
75
 
76
  @app.post(