File size: 1,236 Bytes
acfde9f
 
 
 
 
 
 
 
3847261
acfde9f
 
 
 
 
 
 
 
 
 
575d751
 
e852640
575d751
0db5585
acfde9f
 
 
 
 
 
 
0db5585
acfde9f
0db5585
 
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
37
38
39
40
41
42
43
44
45
46
47
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")
checkpoint = torch.load("Model_IV.pt")

# Define preprocessing
transform = T.Compose([
    T.Resize((224, 224)),  # Adjust to your model's input size
    T.ToTensor(),
])

def predict(image):
    # Preprocess the image by converting the colour space to RGB
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    print("converted the colour to RGB.")
    
    # img_tensor = transform(image).unsqueeze(0)  # Add batch dimension
    
    # # Make prediction
    # with torch.no_grad():
    #     output = model(img_tensor)
    
    # Process output (adjust based on your model's format)
    results = model(image)
    print("ran the model")
    annotated_img = results[0].plot()
    print("got annotated img")
    print("type annotated img:", type(annotated_img))
    
    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()