import gradio as gr
from ultralytics import YOLO
from PIL import Image

#Load model
model = YOLO('yolov8n.pt')

def image_display(input_image):
    # Return the input image as the output
    model = YOLO('yolov8n.pt')
    results = model(input_image)
    for r in results:
        im_array = r.plot()  # plot a BGR numpy array of predictions
        im = Image.fromarray(im_array[..., ::-1])  # RGB PIL image

    return im_array

input_component = gr.Image()
output_component = gr.Image()

# Create the Gradio interface
gr.Interface(
    fn=image_display,
    inputs=input_component,
    outputs=output_component,
    title="Image Display App",
    description="Upload an image and see it displayed.",
    theme="compact"
).launch(share=True)