File size: 1,194 Bytes
1af914e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

from inference import predict, predict_batch

APP_TITLE = "# Fruit & Vegetable Classification"
APP_DESC = """
Model CNN berbasis TensorFlow untuk 15 kelas sayur/buah dari dataset Fresh & Rotten.

- Input  : Foto RGB tunggal, otomatis di-resize ke ukuran input model.
- Output : Probabilitas per kelas (Top-N dari gr.Label).
- Catatan: Gunakan gambar close-up dengan satu objek utama untuk hasil terbaik.
"""

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown(APP_TITLE)
    gr.Markdown(APP_DESC)

    with gr.Row():
        inp = gr.Image(type="pil", label="Upload image (fruit/vegetable)")
        out = gr.Label(num_top_classes=5, label="Predictions")

    with gr.Row():
        btn = gr.Button("Predict", variant="primary")
        gr.ClearButton([inp, out])

    btn.click(predict, inputs=inp, outputs=out, api_name="predict")

    with gr.Tab("Batch (optional)"):
        gal = gr.Gallery(label="Images", columns=4, height="auto")
        out_gal = gr.JSON(label="Batch outputs")
        runb = gr.Button("Run batch")
        runb.click(predict_batch, inputs=gal, outputs=out_gal, api_name="predict_batch")

if __name__ == "__main__":
    demo.launch()