File size: 759 Bytes
65d6dfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
from PIL import Image
import numpy as np

def predict_image(image):
    pipe = pipeline("image-classification", model="itsTomLie/Jaundice_Classifier")

    if isinstance(image, np.ndarray):
        image = Image.fromarray(image.astype('uint8'))
    elif isinstance(image, str): 
        image = Image.open(image)

    result = pipe(image)

    label = result[0]['label']
    confidence = result[0]['score']

    print(f"Prediction: {label}, Confidence: {confidence}")

    return label, confidence

interface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="numpy", label="Upload an Image"),
    outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence")]
)

interface.launch()