File size: 1,647 Bytes
e4fcc21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5effdf
 
 
 
 
 
 
e4fcc21
 
 
 
 
b5effdf
 
 
 
e4fcc21
 
b5effdf
e4fcc21
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
import gradio as gr
from PIL import Image
import pytesseract

import yolov5

# Pytesseract init
choices = pytesseract.get_languages(config='')

def text_inference(filepath, languages):

    return pytesseract.image_to_string(Image.open(filepath), lang=', '.join(languages))

# YOLOv5 Init
model = yolov5.load('nickgambirasi/yolov5s-recycling')

model.conf = 0.2
model.iou = 0.45
model.agnostic = False
model.multi_label = False
model.max_det = 1000

def yolo_inference(image):

    results = model(Image.open(image), size=640)
    predictions = results.pred[0]

    scores = predictions[:, 4]

    return scores

def full_inference(image, languages):

    text_infer = text_inference(image, languages)
    symbol_infer = yolo_inference(image)

    output = {}

    if text_infer:

        output.update({'language_id': 'all_pass'})
        output.update({'text': text_infer})

    
    else:

        output.update({'language_id': 'fail'})

    if any(symbol_infer > model.conf):

        output.update({'symbols': 'all_pass'})

    else:

        output.update({'symbols': 'fail'})

    return output

title = "Hyperintelligent Art Parser"
description = "Gradio deployment of models for text and symbol detection on product labels, powered by Tesseract and YOLOv5"
gr.Interface(
    full_inference,
    [gr.inputs.Image(type="filepath", label="Upload Your Label"), gr.inputs.CheckboxGroup(choices, type="value", default=['eng'], label="Language of Text")],
    'text',
    title=title,
    description=description,
    article=None,
    examples=None
).launch(enable_queue=True)