Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -25,15 +25,8 @@ mushroom_species = {
|
|
25 |
}
|
26 |
|
27 |
# 🎨 Image preprocessing
|
28 |
-
|
29 |
-
|
30 |
-
transforms.Resize((256, 256)),
|
31 |
-
transforms.RandomResizedCrop(224, scale=(0.8, 1.0)),
|
32 |
-
transforms.RandomHorizontalFlip(p=0.5),
|
33 |
-
transforms.RandomVerticalFlip(p=0.3),
|
34 |
-
transforms.RandomRotation(degrees=45),
|
35 |
-
transforms.ColorJitter(brightness=0.3, contrast=0.3, saturation=0.2, hue=0.05),
|
36 |
-
transforms.RandomAffine(degrees=0, translate=(0.1, 0.1), scale=(0.9, 1.1)),
|
37 |
transforms.ToTensor(),
|
38 |
transforms.Normalize([0.485, 0.456, 0.406],
|
39 |
[0.229, 0.224, 0.225])
|
@@ -60,7 +53,7 @@ def classify_mushroom(image: Image.Image):
|
|
60 |
if score < CONFIDENCE_THRESHOLD:
|
61 |
label = "Uncertain"
|
62 |
|
63 |
-
return label, ("กินได้" if label == "Edible" else ("พิษ" if label == "Poisonous" else "ไม่มั่นใจ
|
64 |
|
65 |
except Exception as e:
|
66 |
print(f"❌ Error: {e}")
|
@@ -77,8 +70,7 @@ if __name__ == "__main__":
|
|
77 |
gr.Markdown("Upload a mushroom photo or use your camera to check if it’s edible or poisonous.\nอัปโหลดรูปเห็ดหรือใช้กล้องเพื่อตรวจสอบว่าเห็ดกินได้หรือมีพิษ")
|
78 |
|
79 |
with gr.Row():
|
80 |
-
image_input = gr.Image(type="pil", label="📷 Upload or Capture Mushroom Image")
|
81 |
-
with gr.Column():
|
82 |
label_en = gr.Textbox(label="🧬 Prediction (English)")
|
83 |
label_th = gr.Textbox(label="🔁 คำทำนาย (ภาษาไทย)")
|
84 |
confidence = gr.Textbox(label="📶 Confidence Score")
|
|
|
25 |
}
|
26 |
|
27 |
# 🎨 Image preprocessing
|
28 |
+
transform = transforms.Compose([
|
29 |
+
transforms.Resize((224, 224)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
transforms.ToTensor(),
|
31 |
transforms.Normalize([0.485, 0.456, 0.406],
|
32 |
[0.229, 0.224, 0.225])
|
|
|
53 |
if score < CONFIDENCE_THRESHOLD:
|
54 |
label = "Uncertain"
|
55 |
|
56 |
+
return label, ("กินได้" if label == "Edible" else ("พิษ" if label == "Poisonous" else "ไม่มั่นใจ")), f"{score:.2f}%", suggestion
|
57 |
|
58 |
except Exception as e:
|
59 |
print(f"❌ Error: {e}")
|
|
|
70 |
gr.Markdown("Upload a mushroom photo or use your camera to check if it’s edible or poisonous.\nอัปโหลดรูปเห็ดหรือใช้กล้องเพื่อตรวจสอบว่าเห็ดกินได้หรือมีพิษ")
|
71 |
|
72 |
with gr.Row():
|
73 |
+
image_input = gr.Image(type="pil", label="📷 Upload or Capture Mushroom Image")
|
|
|
74 |
label_en = gr.Textbox(label="🧬 Prediction (English)")
|
75 |
label_th = gr.Textbox(label="🔁 คำทำนาย (ภาษาไทย)")
|
76 |
confidence = gr.Textbox(label="📶 Confidence Score")
|