Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -25,8 +25,15 @@ mushroom_species = {
|
|
25 |
}
|
26 |
|
27 |
# 🎨 Image preprocessing
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
transforms.ToTensor(),
|
31 |
transforms.Normalize([0.485, 0.456, 0.406],
|
32 |
[0.229, 0.224, 0.225])
|
@@ -59,12 +66,9 @@ def classify_mushroom(image: Image.Image):
|
|
59 |
print(f"❌ Error: {e}")
|
60 |
return "Error", "ผิดพลาด", "N/A", "Invalid image. Please upload a valid mushroom photo."
|
61 |
|
62 |
-
# 🔗 Open user manual
|
63 |
MANUAL_URL = "https://drive.google.com/drive/folders/19lUCEaLstrRjCzqpDlWErhRd1EXWUGbf?usp=sharing"
|
64 |
-
|
65 |
-
import webbrowser
|
66 |
-
webbrowser.open_new_tab(MANUAL_URL) # 🆕 Ensure it opens in new tab
|
67 |
-
return "", "", "", "Opening user manual..."
|
68 |
|
69 |
# 🎛️ Gradio UI
|
70 |
if __name__ == "__main__":
|
@@ -73,7 +77,7 @@ if __name__ == "__main__":
|
|
73 |
gr.Markdown("Upload a mushroom photo or use your camera to check if it’s edible or poisonous.\nอัปโหลดรูปเห็ดหรือใช้กล้องเพื่อตรวจสอบว่าเห็ดกินได้หรือมีพิษ")
|
74 |
|
75 |
with gr.Row():
|
76 |
-
image_input = gr.Image(type="pil", label="📷 Upload or Capture Mushroom Image")
|
77 |
with gr.Column():
|
78 |
label_en = gr.Textbox(label="🧬 Prediction (English)")
|
79 |
label_th = gr.Textbox(label="🔁 คำทำนาย (ภาษาไทย)")
|
@@ -81,7 +85,6 @@ if __name__ == "__main__":
|
|
81 |
label_hint = gr.Textbox(label="🏷️ Likely Species (Based on Training Data)")
|
82 |
|
83 |
classify_btn = gr.Button("🔍 Classify")
|
84 |
-
manual_btn = gr.Button("Open User Manual 📄")
|
85 |
|
86 |
classify_btn.click(
|
87 |
fn=classify_mushroom,
|
@@ -89,13 +92,8 @@ if __name__ == "__main__":
|
|
89 |
outputs=[label_en, label_th, confidence, label_hint]
|
90 |
)
|
91 |
|
92 |
-
manual_btn.click(
|
93 |
-
fn=open_manual,
|
94 |
-
inputs=[],
|
95 |
-
outputs=[label_en, label_th, confidence, label_hint]
|
96 |
-
)
|
97 |
-
|
98 |
gr.Markdown("---")
|
99 |
-
gr.Markdown(
|
|
|
100 |
|
101 |
demo.launch()
|
|
|
25 |
}
|
26 |
|
27 |
# 🎨 Image preprocessing
|
28 |
+
# ✅ Define transforms for training and validation
|
29 |
+
train_transform = transforms.Compose([
|
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])
|
|
|
66 |
print(f"❌ Error: {e}")
|
67 |
return "Error", "ผิดพลาด", "N/A", "Invalid image. Please upload a valid mushroom photo."
|
68 |
|
69 |
+
# 🔗 Open user manual (link version) 🆕
|
70 |
MANUAL_URL = "https://drive.google.com/drive/folders/19lUCEaLstrRjCzqpDlWErhRd1EXWUGbf?usp=sharing"
|
71 |
+
manual_link = f"<a href=\"{MANUAL_URL}\" target=\"_blank\">📄 Open User Manual</a>"
|
|
|
|
|
|
|
72 |
|
73 |
# 🎛️ Gradio UI
|
74 |
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", source="upload") # 🆕 safer source usage
|
81 |
with gr.Column():
|
82 |
label_en = gr.Textbox(label="🧬 Prediction (English)")
|
83 |
label_th = gr.Textbox(label="🔁 คำทำนาย (ภาษาไทย)")
|
|
|
85 |
label_hint = gr.Textbox(label="🏷️ Likely Species (Based on Training Data)")
|
86 |
|
87 |
classify_btn = gr.Button("🔍 Classify")
|
|
|
88 |
|
89 |
classify_btn.click(
|
90 |
fn=classify_mushroom,
|
|
|
92 |
outputs=[label_en, label_th, confidence, label_hint]
|
93 |
)
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
gr.Markdown("---")
|
96 |
+
gr.Markdown(manual_link) # 🆕 Display clickable user manual
|
97 |
+
gr.Markdown("App version: 1.0.2 | Updated: August 2025") # 🆕 Version bump
|
98 |
|
99 |
demo.launch()
|