Spaces:
Sleeping
Sleeping
File size: 941 Bytes
acfde9f d823f73 acfde9f 3847261 acfde9f 8ae4fc0 575d751 8ae4fc0 575d751 8ae4fc0 acfde9f 8ae4fc0 cbf9bde 8ae4fc0 cbf9bde 8ae4fc0 c451c54 acfde9f e852640 acfde9f |
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
# import torch
# from PIL import Image
# import torchvision.transforms as T
from ultralytics import YOLO
import cv2
import numpy as np
# Load the PT model
model = YOLO("Model_IV.pt")
def predict(image):
# Preprocessing: Convert the colour space to RGB
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# print("converted the colour to RGB.")
# Make prediction
results = model(image)
#print("ran the model")
# Postprocessing: Convert the colour space back to BGR
annotated_img = results[0].plot()
annotated_img = cv2.cvtColor(annotated_img, cv2.COLOR_RGB2BGR)
# print("converted the colour to BGR.")
return annotated_img
# Gradio interface
demo = gr.Interface(
fn=predict,
inputs=gr.Image(sources=["webcam"], type="numpy"), # Accepts image input
outputs="image" # Customize based on your output format
)
if __name__ == "__main__":
demo.launch() |