trapezius60's picture
Upload 2 files
f2e6302 verified
raw
history blame
1.53 kB
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()