Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,11 +24,25 @@ transform = transforms.Compose([
|
|
| 24 |
|
| 25 |
# Prediction function
|
| 26 |
def predict(image: Image.Image):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|