File size: 1,336 Bytes
33bc438
 
 
 
 
0747d3a
 
33bc438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28aea10
 
 
 
 
40a16da
 
 
 
 
28aea10
 
 
 
 
 
33bc438
 
 
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
44
45
46
47
48
49
50
51
import gradio as gr
from PIL import Image
from transformers import pipeline


 
classifier = pipeline("image-classification", model="Docty/mangoes")

def classify_image(img):
    if not isinstance(img, Image.Image):
        img = Image.fromarray(img)
    results = classifier(img)
    return {res["label"]: float(res["score"]) for res in results}


theme = gr.themes.Soft(
    primary_hue="blue",
    secondary_hue="lime",
    neutral_hue="slate"
)


with gr.Blocks(theme=theme) as demo:
    gr.Markdown("## Mango Image Classifier")
    gr.Markdown("Upload an image of a mango to classify it using a fine-tuned model.")

    with gr.Row():
        image_input = gr.Image(type="pil", label="Upload Mango Image")
        label_output = gr.Label(num_top_classes=3, label="Predictions")

    classify_btn = gr.Button("Classify Image", variant="primary")
    gr.Examples(
        examples=[
            "0.jpg",
            "1.jpg",
            "2.jpg",
            "3.jpg",
            "4.jpg",
            "5.jpg",
            "6.jpg",
            "7.jpg"
        ],
        inputs=image_input,
        outputs=label_output,
        fn=classify_image,
        cache_examples=False  # set True if you want cached predictions
    )
    classify_btn.click(fn=classify_image, inputs=image_input, outputs=label_output)

demo.launch(share=True)