File size: 2,111 Bytes
1a20606
 
2a33ace
f42cf88
1a20606
f42cf88
1a20606
f42cf88
 
 
 
 
 
 
 
 
 
 
 
 
 
5419a54
 
62e40f8
1a20606
 
62e40f8
1a20606
62e40f8
 
f42cf88
62e40f8
7e03464
62e40f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a20606
62e40f8
 
 
 
 
 
 
1a20606
 
62e40f8
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
92
93
94
95
96
97
import gradio as gr
import requests
from AuthVerification import auth_verification
from MinimalScanner import instant_predict

title = "Minimal Scanner, by Proppos"

def js_to_prefere_the_back_camera_of_mobilephones():
    custom_html = """
    <script>
    const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
    
    navigator.mediaDevices.getUserMedia = (constraints) => {
      if (!constraints.video.facingMode) {
        constraints.video.facingMode = {ideal: "environment"};
      }
      return originalGetUserMedia(constraints);
    };
    </script>
    """
    return custom_html


def display_outputs(input_image):
    try:
        instant_predict(input_image)
        return "Image correctly sent to scan with Proppos"
    except Exception as e:
        return f"Error: {e}"

with gr.Blocks(title=title, theme='huggingface', head=js_to_prefere_the_back_camera_of_mobilephones()) as demo_app:
    with gr.Column():
        input_image = gr.Image(type='pil', label='TAKE A PICTURE OF THE TRAY', sources=['webcam'])
        output_comments = gr.Textbox(label='Comments')
        input_image.change(display_outputs, inputs=[input_image], outputs=[output_comments])

demo_app.launch(auth=auth_verification)



























# import gradio as gr
# import requests
# from AuthVerification import auth_verification

# inputs = [gr.Image(type='pil', label='TAKE A PICTURE OF THE TRAY', sources=['webcam', 'clipboard'])]
# outputs = [gr.Textbox(label='Comments')]

# title = "Minimalistic Scanner, by Proppos"

# def instant_predict(pil_image):
#     """
#     Request
#     """
#     print('Sending image to Proppos ...')
#     return 'nice'
    
# def display_outputs(input_image: gr.Image):
#     try:
#         instant_predict(input_image)
#         return "Image correctly sent to scann with Proppos"
#     except Exception as e:
#         return f"Error:{e}"

# demo_app = gr.Interface(
#     fn=display_outputs,
#     inputs=inputs,
#     outputs=outputs,
#     title=title,
#     theme='huggingface'
# )


# demo_app.launch(auth=auth_verification)