File size: 997 Bytes
db34d43
fb13326
 
 
5c2da46
fb13326
 
21f0007
d50b816
fb13326
bc0ea23
 
 
 
fb13326
f23dab3
bc0ea23
7d0861c
ac724cd
23916db
 
 
fb13326
 
f455cfd
32fbb84
23916db
 
c1ff828
f455cfd
fb13326
 
 
 
ba3b687
6fcee56
fb13326
 
 
 
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
import gradio as gr
import torch
from PIL import Image
import torchvision.transforms as T
from ultralytics import YOLO

# Load your model
model = YOLO("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
    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)
    # return output  # or post-process the results as needed
    results = model(image)
    # print(type(results))
    # print(results)
    annotated_img = results[0].plot()
    return annotated_img

# Gradio interface
demo = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="webcam"),  # Accepts image input
    outputs="image"  # Customize based on your output format
)

if __name__ == "__main__":
    demo.launch()