File size: 1,307 Bytes
77f8d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
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()