File size: 1,787 Bytes
40dcf79
 
d8c5837
40dcf79
 
d8c5837
 
40dcf79
54ce086
 
a466d2a
40dcf79
d8c5837
40dcf79
7b8d56f
d8c5837
 
 
 
 
 
 
 
40dcf79
d8c5837
40dcf79
 
d8c5837
 
 
 
e68532b
 
 
d1ed39f
 
 
 
 
 
e68532b
40dcf79
d8c5837
 
451d332
40dcf79
d8c5837
 
40dcf79
 
d8c5837
 
40dcf79
 
 
d8c5837
 
 
 
40dcf79
614769f
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
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
import yolov5
import os
from transformers import pipeline

imageClassifier = pipeline(task="image-classification",
                           model="PranomVignesh/Police-vs-Public")



model = yolov5.load('./best.pt', device="cpu")

def predict(image):
    results = model([image], size=224)
    print(results)
    predictions = imageClassifier(image)
    classMappings = {
        'police': "Police / Authorized Personnel",
        'public': 'Unauthorized Person'
    }
    output = {}
    for item in predictions:
        output[classMappings[item['label']]] = item['score']

    return results.render()[0], output


title = "Detecting Unauthorized Individuals with Firearms"
description = """
  Try the examples at bottom to get started.
"""
examples = [
    [os.path.join(os.path.abspath(''), './examples/sample_1.png')],
    [os.path.join(os.path.abspath(''), './examples/sample_2.png')],
    [os.path.join(os.path.abspath(''), './examples/sample_3.jpg')],
    [os.path.join(os.path.abspath(''), './examples/sample_4.jpg')],
    [os.path.join(os.path.abspath(''), './examples/sample_5.jpg')],
    [os.path.join(os.path.abspath(''), './examples/sample_6.jpg')],
    [os.path.join(os.path.abspath(''), './examples/sample_7.jpg')],
    [os.path.join(os.path.abspath(''), './examples/sample_8.jpg')],
]

inputs = gr.Image(type="pil", shape=(224, 224),
                  label="Upload your image for detection")

outputs = [
    gr.Image(type="pil", label="Gun Detections"),
    gr.Label(label="Class Prediction")
]

interface = gr.Interface(
    fn=predict,
    inputs=inputs,
    outputs=outputs,
    title=title,
    examples=examples,
    description=description,
    cache_examples=True,
    theme='huggingface'
)
interface.launch(debug=True, enable_queue=True)