upload application
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from utils import extraire_informations_carte,make_prediction
|
| 4 |
+
|
| 5 |
+
def predict(img):
|
| 6 |
+
proba, document_type = make_prediction(img)
|
| 7 |
+
if proba < .98:
|
| 8 |
+
return "Ce document ne fait pas partir de ceux pris en charge actuelement (Nouvelle et Ancienne CNI, Permis de conduire)"
|
| 9 |
+
else :
|
| 10 |
+
doc_type = document_type +1
|
| 11 |
+
result = extraire_informations_carte(img,doc_type)
|
| 12 |
+
return result
|
| 13 |
+
|
| 14 |
+
image = gr.components.Image(type = "filepath")
|
| 15 |
+
#type_document = gr.components.Dropdown(["Nouvelle_CNI","ANCIENNE_CNI","PERMIS_DE_CONDUITE"])
|
| 16 |
+
out_lab = gr.components.Textbox()
|
| 17 |
+
|
| 18 |
+
### 4. Gradio app ###
|
| 19 |
+
# Create title, description and article strings
|
| 20 |
+
title = "OCR FOR IMAGES ANALYSIS"
|
| 21 |
+
description = "WE USE OCR TO EXTRACT INFORMATIONS FROM DIFFERENT TYPES OF DOCUMENTS AND FORMALIZE THE RESULT INTO JSON."
|
| 22 |
+
article = "Created by data354."
|
| 23 |
+
|
| 24 |
+
# Create examples list from "examples/" directory
|
| 25 |
+
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
| 26 |
+
print(example_list)
|
| 27 |
+
#[gr.Label(label="Predictions"), # what are the outputs?
|
| 28 |
+
#gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
|
| 29 |
+
# Create examples list from "examples/" directory
|
| 30 |
+
# Create the Gradio demo
|
| 31 |
+
demo = gr.Interface(fn=predict, # mapping function from input to output
|
| 32 |
+
inputs= image, #gr.Image(type="pil"), # what are the inputs?
|
| 33 |
+
outputs=out_lab, #[list of outputs]
|
| 34 |
+
examples=example_list,
|
| 35 |
+
title=title,
|
| 36 |
+
description=description,
|
| 37 |
+
article=article
|
| 38 |
+
)
|
| 39 |
+
# Launch the demo!
|
| 40 |
+
demo.launch(debug = True)
|