| import gradio as gr | |
| from code.detection.recognize_id.detect_and_recognize_id import Recognize_ID | |
| from code.detection.detection import detection | |
| from code.recognization.recognization import TextRecognition | |
| import os | |
| # Define a dummy prediction function | |
| def predict_image(image): | |
| # Recognize ID | |
| rec_id = Recognize_ID() | |
| id = rec_id.give_me_id_number(image) | |
| # Detection | |
| det = detection() | |
| detection_list = det.full_pipeline(image) | |
| result = '' | |
| # Loop on all detected images and recognize them | |
| recognizer = TextRecognition() | |
| for line in detection_list[2:6]: | |
| for word in line: | |
| recognized_word = recognizer.recognize_image(word) | |
| result = result + recognized_word + ' ' | |
| result += '\n' | |
| # Add Id number | |
| result = result + id | |
| return result | |
| # List of paths to your sample images | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| sample_images = [ | |
| os.path.join(current_dir , "samples/id_1.png" ) | |
| ] | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=predict_image, # Function to run | |
| inputs="image", # Input type | |
| outputs="text", # Output type | |
| title="Recognization", | |
| description="Upload an image", | |
| examples=sample_images | |
| ) | |
| # Launch the app | |
| interface.launch() | |