File size: 3,006 Bytes
b83366b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ccb231
 
 
b83366b
5ccb231
b83366b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ccb231
b83366b
5ccb231
b83366b
80f0cfc
b83366b
 
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
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):
    # 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"}]
       
        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>Credit Card OCR</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')
            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], outputs=[json_output])

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

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