File size: 1,683 Bytes
8e212da
 
8e1a289
8e212da
8e1a289
 
 
 
 
 
 
 
8e212da
 
8e1a289
8e212da
 
 
 
 
 
 
 
 
8e1a289
8e212da
 
 
 
 
 
8e1a289
 
8e212da
 
 
 
 
 
 
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 os
from utils import extraire_informations_carte,make_prediction

def predict(img):
    proba, document_type = make_prediction(img)
    if proba < .98:
        return "Ce document ne fait pas partir de ceux pris en charge actuelement (Nouvelle et Ancienne CNI, Permis de conduire)"
    else :
        doc_type = document_type +1
        result = extraire_informations_carte(img,doc_type)
        return result

image = gr.components.Image(type = "filepath")
#type_document = gr.components.Dropdown(["Nouvelle_CNI","ANCIENNE_CNI","PERMIS_DE_CONDUITE"])
out_lab = gr.components.Textbox()

### 4. Gradio app ###
# Create title, description and article strings
title = "OCR FOR IMAGES ANALYSIS"
description = "WE USE OCR TO EXTRACT INFORMATIONS FROM DIFFERENT TYPES OF DOCUMENTS AND FORMALIZE THE RESULT INTO JSON."
article = "Created by data354."

# Create examples list from "examples/" directory
example_list = [["examples/" + example] for example in os.listdir("examples")]
print(example_list)
#[gr.Label(label="Predictions"), # what are the outputs?
#gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
# Create examples list from "examples/" directory
# Create the Gradio demo
demo = gr.Interface(fn=predict, # mapping function from input to output
                    inputs= image, #gr.Image(type="pil"), # what are the inputs?
                    outputs=out_lab, #[list of outputs]
                    examples=example_list, 
                    title=title,
                    description=description,
                    article=article
                   )
# Launch the demo!
demo.launch(debug = True)