Ayamohamed commited on
Commit
dbd5e78
·
verified ·
1 Parent(s): 637c47d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -14,13 +14,25 @@ transform = transforms.Compose([
14
  transforms.ToTensor(),
15
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
16
  ])
 
 
17
  def predict(image):
18
- image = transform(image).unsqueeze(0)
19
- with torch.no_grad():
20
- output = local_model(image)
21
- probabilities = F.softmax(output, dim=1)
22
- class_idx = torch.argmax(probabilities, dim=1).item()
23
- return "Diagram" if class_idx == 0 else "Not Diagram"
 
 
 
 
 
 
 
 
 
 
24
 
25
  gr.Interface(
26
  fn=predict,
 
14
  transforms.ToTensor(),
15
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
16
  ])
17
+
18
+
19
  def predict(image):
20
+ try:
21
+ print("Received image:", image)
22
+ image = transform(image).unsqueeze(0)
23
+ print("Transformed image shape:", image.shape)
24
+
25
+ # Model inference
26
+ with torch.no_grad():
27
+ output = model(image)
28
+ print("Model output:", output)
29
+ class_idx = torch.argmax(output, dim=1).item()
30
+
31
+ return "Diagram" if class_idx == 1 else "Not Diagram"
32
+
33
+ except Exception as e:
34
+ print("Error during prediction:", str(e))
35
+ return f"Prediction Error: {str(e)}"
36
 
37
  gr.Interface(
38
  fn=predict,