Spaces:
Sleeping
Sleeping
File size: 1,662 Bytes
8e212da 3786303 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 41 |
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) |