Spaces:
Build error
Build error
File size: 1,534 Bytes
f2e6302 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
from PIL import Image
import random
# 💡 Placeholder classifier — replace with actual model or API call
def classify_mushroom(image):
# Simulate prediction
prediction = random.choice(["Edible", "Poisonous"])
confidence = round(random.uniform(0.7, 0.99), 2)
bilingual_map = {
"Edible": "กินได้",
"Poisonous": "พิษ"
}
return {
"Prediction (EN)": prediction,
"คำทำนาย (TH)": bilingual_map[prediction],
"Confidence": f"{confidence * 100:.1f}%"
}
# 🧪 Gradio App UI
with gr.Blocks() as demo:
gr.Markdown("## 🍄 Mushroom Safety Classifier")
gr.Markdown("Upload a photo of a mushroom to check if it's edible or poisonous.\nอัปโหลดรูปเห็ดเพื่อทำนายว่าเห็ดกินได้หรือมีพิษ")
with gr.Row():
image_input = gr.Image(type="pil", label="📷 Upload Mushroom Image")
with gr.Column():
label_en = gr.Textbox(label="🧠 Prediction (English)")
label_th = gr.Textbox(label="🗣️ คำทำนาย (ภาษาไทย)")
confidence = gr.Textbox(label="📶 Confidence Score")
classify_btn = gr.Button("🔍 Classify")
# 🔁 Connect button to function
classify_btn.click(
fn=classify_mushroom,
inputs=image_input,
outputs=[label_en, label_th, confidence]
)
demo.launch() |