File size: 4,239 Bytes
e388f06
 
 
 
 
 
 
 
 
 
2ef56a6
e388f06
 
 
 
 
 
 
 
 
 
 
 
8232579
2ef56a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8232579
e388f06
8232579
e388f06
 
 
 
 
 
 
10dd417
e388f06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ef56a6
 
 
 
e388f06
 
 
 
 
 
2ef56a6
e388f06
6382e93
e388f06
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import gradio as gr
import requests
import json
import io
from gradio.components import Image
from PIL import Image as PILImage, ImageDraw, ImageFont  # This import may be needed if you're processing images

from PIL import Image

def process_image(image, screenReplyThreshold, printedCopyThreshold, portraitReplaceThreshold):
    # Convert PIL image to bytes to send in POST request
    img_bytes = io.BytesIO()
    image.save(img_bytes, format="JPEG")
    img_bytes.seek(0)
    
    
    url = "http://127.0.0.1:9000/process_image"
    files = {'image': img_bytes}
    result = requests.post(url=url, files=files)
    if result.ok:
        json_result = result.json()
        if json_result.get("resultCode") == "Error":
            return {"resultCode": "Error", "result": "Failed to process image"}

        process_results = json_result.get("result")
        status = process_results.get("status")
        if status == "Ok":
            screenReply = process_results.get("screenReply")
            portraitReplace = process_results.get("portraitReplace")
            printedCopy = process_results.get("printedCopy")

            # Check for "Spoof" condition
            if screenReply < screenReplyThreshold or portraitReplace < portraitReplaceThreshold or printedCopy < printedCopyThreshold:
                process_results["status"] = "Spoof"
            else:
                process_results["status"] = "Real"

            # Update json_result with the modified process_results
            json_result["result"] = process_results
        return json_result
    else:
        return {"resultCode": "Error", "result": result.text}
    
with gr.Blocks() as demo:
    gr.Markdown(
        """
        <div style="display: flex;align-items: center;">
            <img alt="Opulentyn Logo" src="https://github.com/user-attachments/assets/5fc78032-bff2-4f7e-a174-7d64b22f506d" width="350"/>
            <div>
                <h1>ID Document Liveness Detection</h1>
                <p>We offer <b>on-premises</b> OCR and liveness check solutions available with a <b>perpetual license</b>.</p>
            </div>
        </div>
        
        ## 🤝 Talk to us
        
        <div style="display: flex; align-items: center;">
            <a href="https://opulentyn.com" target="_blank">
                <img src="https://img.shields.io/badge/Website-https%3A%2F%2Fopulentyn.com-blue?style=flat&logo=google-chrome&logoColor=white" alt="Website">
            </a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="mailto:support@opulentyn.com">
                <img src="https://img.shields.io/badge/Email-support%40opulentyn.com-blue?style=flat&logo=gmail&logoColor=white" alt="Email">
            </a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="https://join.slack.com/t/opulentyn/shared_invite/zt-2s230jtbq-dWBs8XUZcrYim~nUqiimSA" target="_blank">
                <img src="https://img.shields.io/badge/Slack-support--sdk-blueviolet?style=flat&logo=slack&logoColor=white" alt="Slack">
            </a>
        </div>
        """
    )

    with gr.Row():
        with gr.Column():
            image_input = gr.Image(type='pil')
            screenReplyThreshold = gr.Slider(minimum=0, maximum=1, value=0.5, label="Screen Reply Threshold")
            printedCopyThreshold = gr.Slider(minimum=0, maximum=1, value=0.5, label="Printed Copy Threshold")
            portraitReplaceThreshold = gr.Slider(minimum=0, maximum=1, value=0.5, label="Portrait Replace Threshold")
            
            gr.Examples(['examples/1.jpg', 'examples/2.jpg', 'examples/3.jpg'], 
                        inputs=image_input)
            process_button = gr.Button("Process")
        with gr.Column():
            json_output = gr.JSON()
    
    process_button.click(process_image, inputs=[image_input, screenReplyThreshold, printedCopyThreshold, portraitReplaceThreshold], outputs=[json_output])

    gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FIDDocLive"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FIDDocLive&countColor=%23263759" /></a>')

demo.launch(server_name="0.0.0.0", server_port=7860)