Joodson commited on
Commit
97891e0
·
verified ·
1 Parent(s): 73ace6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -24,11 +24,25 @@ transform = transforms.Compose([
24
 
25
  # Prediction function
26
  def predict(image: Image.Image):
27
- tensor = transform(image).unsqueeze(0)
28
- with torch.no_grad():
29
- logits = model(tensor).logits
30
- predicted = torch.argmax(logits, dim=1).item()
31
- return config.id2label[str(predicted)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  # ✅ Prediction interface
34
  gr.Interface(
 
24
 
25
  # Prediction function
26
  def predict(image: Image.Image):
27
+ try:
28
+ print("🔍 Received image:", image)
29
+
30
+ tensor = transform(image).unsqueeze(0) # Add batch dimension
31
+ print("📦 Transformed tensor shape:", tensor.shape)
32
+
33
+ with torch.no_grad():
34
+ logits = model(tensor).logits
35
+ predicted = torch.argmax(logits, dim=1).item()
36
+ print("✅ Prediction index:", predicted)
37
+
38
+ label = config.id2label[str(predicted)]
39
+ print("🏷️ Label:", label)
40
+ return label
41
+
42
+ except Exception as e:
43
+ print("❌ Prediction error:", e)
44
+ return "خطأ"
45
+
46
 
47
  # ✅ Prediction interface
48
  gr.Interface(