File size: 680 Bytes
4b45220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import json
from PIL import Image
from tensorflow.keras.models import load_model
from helpers import detect_image

model = load_model("yolo_model.keras", compile=False)
with open("anchors.json") as f: anchors = json.load(f)
with open("labels.json") as f: labels = json.load(f)

def predict(image):
    if image is None: return None
    return detect_image(image.convert("RGB"), model, anchors, labels)

demo = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil", label="Upload image"),
    outputs=gr.Image(type="pil", label="Detections"),
    title="YOLO Object Detection",
    allow_flagging="never",
)

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