OCR_Project / app.py
youl's picture
update
3786303 verified
raw
history blame
1.66 kB
import gradio as gr
import os
from utils import extraire_informations_carte
def predict(img, type_doc):
data = {"Nouvelle_CNI":1,"ANCIENNE_CNI":2,"PERMIS_DE_CONDUITE":3}
type_document = data[type_doc]
result = extraire_informations_carte(img,type_document)
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,i] for example,i in zip(os.listdir("examples"),["ANCIENNE_CNI","ANCIENNE_CNI","Nouvelle_CNI","Nouvelle_CNI","Nouvelle_CNI","PERMIS_DE_CONDUITE","PERMIS_DE_CONDUITE"])]
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,type_document], #gr.Image(type="pil"), # what are the inputs?
outputs=out_lab,
examples=example_list,
title=title,
description=description,
article=article
)
# Launch the demo!
demo.launch(debug = True)