Glainez commited on
Commit
cd72428
·
1 Parent(s): ad3160b

patient_id can be informed manually or by image

Browse files
Files changed (2) hide show
  1. app.py +22 -5
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- #from pyzbar.pyzbar import decode
3
  from lambdas import upload_models, predict
4
  import base64
5
  from io import BytesIO, StringIO
@@ -32,7 +32,7 @@ def login(username, password) -> bool:
32
  restaurant_name = str(row['restaurant_name'])
33
  mode = 'waste'
34
  possible_modes = str(row.get('modes')).split(':')
35
- possible_shifts = {i.split(':')[0]: i.split(':')[1] for i in str(row.get('shifts')).split('-')} \
36
  if row.get('shifts') else {'no shift': None}
37
 
38
  config_aux = {'restaurant_id': restaurant_id,
@@ -113,6 +113,7 @@ with (gr.Blocks(head=prefer_frontal_cam_html, css=css_image_aspect_ratio) as blo
113
 
114
 
115
  gr.Markdown(""" * Do you have any doubt? Please, see the documentation tab. \n
 
116
  * Tens un dubte? Consulta la pestanya de documentació. """)
117
 
118
  logout_button = gr.Button(link='/logout', value='Logout / Exit ↩', size='sm')
@@ -129,9 +130,25 @@ with (gr.Blocks(head=prefer_frontal_cam_html, css=css_image_aspect_ratio) as blo
129
  type='pil',
130
  show_share_button=False,
131
  show_download_button=False,
132
- height=720, width=1280, min_width=0,
133
  elem_id="image-container")
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  ## Patient ID searcher. Uncomment if needed
136
  # with gr.Accordion(open=False):
137
  # eater_id = gr.Textbox(label='Patient Identification', placeholder='Searching Patient ID')
@@ -148,10 +165,10 @@ with (gr.Blocks(head=prefer_frontal_cam_html, css=css_image_aspect_ratio) as blo
148
  # final_value = new_value if new_value != default_value else current_value
149
  # current_eater_id['value'] = final_value
150
  # return final_value
151
- eater_id = None
152
 
153
  b = gr.Button('PRESS TO PREDICT')
154
- b.click(fn=predict_app, inputs=[im], outputs=gr.Info()) # add eater id to input if needed
155
 
156
  with gr.Tab(label='ℹ️ Status', id=2):
157
  gr.Markdown(' Press the button to see the status of the Application and technical information')
 
1
  import gradio as gr
2
+ from pyzbar.pyzbar import decode
3
  from lambdas import upload_models, predict
4
  import base64
5
  from io import BytesIO, StringIO
 
32
  restaurant_name = str(row['restaurant_name'])
33
  mode = 'waste'
34
  possible_modes = str(row.get('modes')).split(':')
35
+ possible_shifts = {i.split(':')[0]: int(i.split(':')[1]) for i in str(row.get('shifts')).split('-')} \
36
  if row.get('shifts') else {'no shift': None}
37
 
38
  config_aux = {'restaurant_id': restaurant_id,
 
113
 
114
 
115
  gr.Markdown(""" * Do you have any doubt? Please, see the documentation tab. \n
116
+ * Tienes alguna duda? Consulta la pestaña de documentación
117
  * Tens un dubte? Consulta la pestanya de documentació. """)
118
 
119
  logout_button = gr.Button(link='/logout', value='Logout / Exit ↩', size='sm')
 
130
  type='pil',
131
  show_share_button=False,
132
  show_download_button=False,
133
+ height='720px', width='1280px', min_width=0,
134
  elem_id="image-container")
135
 
136
+
137
+ ## Patient ID searcher.
138
+ with gr.Accordion(open=False):
139
+ def get_barcode_from_image(image):
140
+ if not image:
141
+ raise gr.Error('No image has been taken yet')
142
+ d = decode(image)
143
+ if not d:
144
+ raise gr.Error('Cannot find a barcode on the Image')
145
+ barcode = d[0].data.decode('utf8') if d else None
146
+ return barcode
147
+ get_barcode_button = gr.Button('Get Patient ID (Barcode) from Image')
148
+ eater_id = gr.Textbox(label='Patient ID', interactive=True, value=None,
149
+ placeholder='Write the patient id or take a photo')
150
+ get_barcode_button.click(fn=get_barcode_from_image, inputs=[im], outputs=eater_id)
151
+
152
  ## Patient ID searcher. Uncomment if needed
153
  # with gr.Accordion(open=False):
154
  # eater_id = gr.Textbox(label='Patient Identification', placeholder='Searching Patient ID')
 
165
  # final_value = new_value if new_value != default_value else current_value
166
  # current_eater_id['value'] = final_value
167
  # return final_value
168
+ # eater_id = None
169
 
170
  b = gr.Button('PRESS TO PREDICT')
171
+ b.click(fn=predict_app, inputs=[im, eater_id], outputs=gr.Info()) # add eater id to input if needed
172
 
173
  with gr.Tab(label='ℹ️ Status', id=2):
174
  gr.Markdown(' Press the button to see the status of the Application and technical information')
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  pillow
2
  boto3
 
 
1
  pillow
2
  boto3
3
+ pyzbar