Spaces:
Sleeping
Sleeping
| 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) |