File size: 1,217 Bytes
faf0cee
 
 
 
 
 
 
133fa5d
faf0cee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445cc2d
faf0cee
 
445cc2d
faf0cee
 
c7c7061
 
faf0cee
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
48
49
#import gradio as gr
#from ultralytics import YOLO

#def greet(name):
#    return "Hello " + name + "!!"

#demo = gr.Interface(fn=greet, inputs="text", outputs="text")

#demo.launch()

from ultralytics import YOLO
from PIL import Image
import gradio as gr
from huggingface_hub import snapshot_download
import os

model_path = "best_int8_openvino_model"

def load_model(repo_id):
    download_dir = snapshot_download(repo_id)
    print(download_dir)
    path  = os.path.join(download_dir, "best_int8_openvino_model")
    print(path)
    detection_model = YOLO(path, task='detect')
    
    return detection_model


def predict(pilimg):

    source = pilimg
    # x = np.asarray(pilimg)
    # print(x.shape)
    result = detection_model.predict(source, conf=0.5, iou=0.6)
    img_bgr = result[0].plot()
    out_pilimg = Image.fromarray(img_bgr[..., ::-1])  # RGB-order PIL image
    
    return out_pilimg



REPO_ID = "ITI107-2024S2/6304871K"
detection_model = load_model(REPO_ID)
title = "Detection of Pineapple and Sweet Potato in uploaded Image"
gr.Interface(fn=predict,
             inputs=gr.Image(type="pil"),
             outputs=gr.Image(type="pil"),
             title=title,
             ).launch(share=True)