Spaces:
Runtime error
Runtime error
File size: 1,016 Bytes
e0e7956 |
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 |
import gradio as gr
from fastai.vision.all import load_learner, PILImage
# โหลดโมเดล
model = load_learner("my_fastai_model.pkl")
# ฟังก์ชันพยากรณ์ชนิดของดินจากภาพ
def classify_soil(img):
pred_class, pred_idx, probs = model.predict(PILImage.create(img))
return {model.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
# UI ด้วย Gradio
interface = gr.Interface(
fn=classify_soil,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="Soil Type Classifier",
description="อัปโหลดภาพของดิน ระบบจะพยากรณ์ว่าเป็นดินชนิดใด เช่น ดินเหนียว ดินร่วน ดินทราย เป็นต้น",
examples=["clay_soil.jpg", "sandy_soil.jpg", "loamy_soil.jpg"]
)
# เรียกใช้งาน
if __name__ == "__main__":
interface.launch()
|