Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +43 -0
- requirements.txt.txt +8 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import random
|
4 |
+
|
5 |
+
# 💡 Placeholder classifier — replace with actual model or API call
|
6 |
+
def classify_mushroom(image):
|
7 |
+
# Simulate prediction
|
8 |
+
prediction = random.choice(["Edible", "Poisonous"])
|
9 |
+
confidence = round(random.uniform(0.7, 0.99), 2)
|
10 |
+
|
11 |
+
bilingual_map = {
|
12 |
+
"Edible": "กินได้",
|
13 |
+
"Poisonous": "พิษ"
|
14 |
+
}
|
15 |
+
|
16 |
+
return {
|
17 |
+
"Prediction (EN)": prediction,
|
18 |
+
"คำทำนาย (TH)": bilingual_map[prediction],
|
19 |
+
"Confidence": f"{confidence * 100:.1f}%"
|
20 |
+
}
|
21 |
+
|
22 |
+
# 🧪 Gradio App UI
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
gr.Markdown("## 🍄 Mushroom Safety Classifier")
|
25 |
+
gr.Markdown("Upload a photo of a mushroom to check if it's edible or poisonous.\nอัปโหลดรูปเห็ดเพื่อทำนายว่าเห็ดกินได้หรือมีพิษ")
|
26 |
+
|
27 |
+
with gr.Row():
|
28 |
+
image_input = gr.Image(type="pil", label="📷 Upload Mushroom Image")
|
29 |
+
with gr.Column():
|
30 |
+
label_en = gr.Textbox(label="🧠 Prediction (English)")
|
31 |
+
label_th = gr.Textbox(label="🗣️ คำทำนาย (ภาษาไทย)")
|
32 |
+
confidence = gr.Textbox(label="📶 Confidence Score")
|
33 |
+
|
34 |
+
classify_btn = gr.Button("🔍 Classify")
|
35 |
+
|
36 |
+
# 🔁 Connect button to function
|
37 |
+
classify_btn.click(
|
38 |
+
fn=classify_mushroom,
|
39 |
+
inputs=image_input,
|
40 |
+
outputs=[label_en, label_th, confidence]
|
41 |
+
)
|
42 |
+
|
43 |
+
demo.launch()
|
requirements.txt.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.28.3 # For the app UI
|
2 |
+
pillow # For image processing (PIL)
|
3 |
+
torch # For PyTorch-based image models
|
4 |
+
torchvision # Optional: for pretrained models like ResNet
|
5 |
+
requests # Useful for connecting to hosted APIs (e.g. Roboflow)
|
6 |
+
transformers # For Hugging Face models (image-classification pipeline)
|
7 |
+
opencv-python # Optional: for image pre-processing / GradCAM
|
8 |
+
matplotlib # Optional: for visual overlays like heatmaps
|