| | import gradio as gr |
| | from ultralytics import YOLO |
| | import numpy as np |
| | from PIL import Image |
| |
|
| | |
| | model = YOLO("YOLOV_8_model.pt") |
| |
|
| | def segment_conjunctiva(image): |
| | |
| | if not isinstance(image, Image.Image): |
| | raise ValueError("Input is not a valid image") |
| |
|
| | image = image.convert("RGB") |
| | |
| | png_converted = Image.new("RGB", image.size) |
| | png_converted.paste(image) |
| |
|
| | |
| | image_np = np.array(png_converted) |
| |
|
| | |
| | results = model(source=image_np, conf=0.5) |
| |
|
| | |
| | if results[0].masks is None: |
| | print("⚠️ No segmentation masks detected") |
| |
|
| | |
| | annotated_img = results[0].plot() |
| |
|
| | return annotated_img |
| |
|
| | |
| | title = "👁️Conjunctiva Segmentation using YOLOv8" |
| | description = "Upload an eye image in any format (JPG/PNG/etc). This app uses a YOLOv8 segmentation model to segment the palpebral conjunctiva." |
| |
|
| | demo = gr.Interface( |
| | fn=segment_conjunctiva, |
| | inputs=gr.Image(type="pil"), |
| | outputs=gr.Image(type="numpy"), |
| | title=title, |
| | description=description, |
| | examples=[], |
| | ) |
| |
|
| | demo.launch() |
| |
|