Glainez commited on
Commit
beee895
·
1 Parent(s): bed5116

change Image Aspect ratio to be fixed

Browse files
Files changed (2) hide show
  1. app.py +24 -15
  2. descriptions.py +28 -3
app.py CHANGED
@@ -8,7 +8,7 @@ import pandas as pd
8
  import os.path
9
  import numpy as np
10
  from datetime import datetime, timedelta
11
- from descriptions import prefer_frontal_cam_html, docu_eng, docu_cat
12
 
13
  DEBUG = True
14
 
@@ -69,7 +69,7 @@ def start_app(shift_id, mode, date):
69
  return gr.Tabs(selected=tab_id, visible=True)
70
 
71
 
72
- def predict_app(image, patient_id):
73
  gr.Info('Predicting ...')
74
  buffered = BytesIO()
75
  image.save(buffered, format='JPEG')
@@ -84,17 +84,17 @@ def predict_app(image, patient_id):
84
 
85
 
86
  # APP
87
- with (gr.Blocks(head=prefer_frontal_cam_html) as block):
88
  with gr.Tabs() as tabs:
89
  with gr.Tab(label='Welcome', id=0) as welcome_tab:
90
  gr.Info('Loading ...')
 
 
91
  @gr.render()
92
  def header():
93
  gr.Markdown(f'# User: {config.get("restaurant_name", "Proppos")}', render=True)
94
 
95
 
96
- logout_button = gr.Button(icon=None, link='/logout', value='Logout / Exit ↩')
97
-
98
  @gr.render()
99
  def render_dropdowns():
100
  shift_dropdown = gr.Dropdown(label='Meal/Apat/Comida',
@@ -111,6 +111,7 @@ with (gr.Blocks(head=prefer_frontal_cam_html) as block):
111
  start_button = gr.Button(value='START ▶️')
112
  start_button.click(fn=start_app, inputs=[shift_dropdown, mode_dropdown, date_chooser], outputs=tabs)
113
 
 
114
  gr.Markdown(""" * Do you have any doubt? Please, see the documentation tab. \n
115
  * Tens un dubte? Consulta la pestanya de documentació. """)
116
 
@@ -123,13 +124,19 @@ with (gr.Blocks(head=prefer_frontal_cam_html) as block):
123
  3. Place the tray so it is centered in the displayed image and
124
  4. Press the grey button 'PRESS TO PREDICT'
125
  """)
126
- im = gr.Image(sources=['webcam'], streaming=True, mirror_webcam=False, type='pil',
127
- height=720, width=1280)
128
- with gr.Accordion():
129
- eater_id = gr.Textbox(label='Patient Identification', placeholder='Searching Patient ID')
130
-
131
- current_eater_id = {'value': None}
132
-
 
 
 
 
 
 
133
 
134
  # @gr.on(inputs=im, outputs=eater_id)
135
  # def search_eater_id(image):
@@ -141,10 +148,12 @@ with (gr.Blocks(head=prefer_frontal_cam_html) as block):
141
  # final_value = new_value if new_value != default_value else current_value
142
  # current_eater_id['value'] = final_value
143
  # return final_value
144
-
145
 
146
  b = gr.Button('PRESS TO PREDICT')
147
- b.click(fn=predict_app, inputs=[im, eater_id], outputs=gr.Info())
 
 
148
 
149
  with gr.Tab(label='ℹ️ Status', id=2):
150
  gr.Markdown(' Press the button to see the status of the Application and technical information')
@@ -156,11 +165,11 @@ with (gr.Blocks(head=prefer_frontal_cam_html) as block):
156
  choices = [('ENG 🇬🇧', docu_eng), ('CAT', docu_cat)]
157
  c = gr.Radio(label='Select the language', choices=choices)
158
 
 
159
  @gr.render()
160
  def display_docu():
161
  d = gr.Markdown(docu_eng)
162
  c.change(fn=lambda x: x, inputs=c, outputs=d)
163
 
164
 
165
-
166
  block.launch(show_api=False, auth=login)
 
8
  import os.path
9
  import numpy as np
10
  from datetime import datetime, timedelta
11
+ from descriptions import prefer_frontal_cam_html, docu_eng, docu_cat, css_image_aspect_ratio
12
 
13
  DEBUG = True
14
 
 
69
  return gr.Tabs(selected=tab_id, visible=True)
70
 
71
 
72
+ def predict_app(image, patient_id=None):
73
  gr.Info('Predicting ...')
74
  buffered = BytesIO()
75
  image.save(buffered, format='JPEG')
 
84
 
85
 
86
  # APP
87
+ with (gr.Blocks(head=prefer_frontal_cam_html, css=css_image_aspect_ratio) as block):
88
  with gr.Tabs() as tabs:
89
  with gr.Tab(label='Welcome', id=0) as welcome_tab:
90
  gr.Info('Loading ...')
91
+
92
+
93
  @gr.render()
94
  def header():
95
  gr.Markdown(f'# User: {config.get("restaurant_name", "Proppos")}', render=True)
96
 
97
 
 
 
98
  @gr.render()
99
  def render_dropdowns():
100
  shift_dropdown = gr.Dropdown(label='Meal/Apat/Comida',
 
111
  start_button = gr.Button(value='START ▶️')
112
  start_button.click(fn=start_app, inputs=[shift_dropdown, mode_dropdown, date_chooser], outputs=tabs)
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
 
 
124
  3. Place the tray so it is centered in the displayed image and
125
  4. Press the grey button 'PRESS TO PREDICT'
126
  """)
127
+ im = gr.Image(sources=['webcam'],
128
+ mirror_webcam=False,
129
+ type='pil',
130
+ show_share_button=False,
131
+ show_download_button=False,
132
+ height=720, width=1280,
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')
138
+ #
139
+ # current_eater_id = {'value': None}
140
 
141
  # @gr.on(inputs=im, outputs=eater_id)
142
  # def search_eater_id(image):
 
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
+ logout_button = gr.Button(link='/logout', value='Logout / Exit ↩', size='sm')
157
 
158
  with gr.Tab(label='ℹ️ Status', id=2):
159
  gr.Markdown(' Press the button to see the status of the Application and technical information')
 
165
  choices = [('ENG 🇬🇧', docu_eng), ('CAT', docu_cat)]
166
  c = gr.Radio(label='Select the language', choices=choices)
167
 
168
+
169
  @gr.render()
170
  def display_docu():
171
  d = gr.Markdown(docu_eng)
172
  c.change(fn=lambda x: x, inputs=c, outputs=d)
173
 
174
 
 
175
  block.launch(show_api=False, auth=login)
descriptions.py CHANGED
@@ -11,7 +11,7 @@ navigator.mediaDevices.getUserMedia = (constraints) => {
11
  </script>
12
  """
13
 
14
- docu_eng="""
15
  ## User Guide
16
 
17
  This application is intended to create the multiple
@@ -89,8 +89,7 @@ Some of the info can be pretty technical.
89
  Thank you for using our application! We hope this guide helps you navigate and use all the features effectively.
90
  """
91
 
92
-
93
- docu_cat="""
94
  ## Guia d'Usuari
95
 
96
  Aquesta aplicació està destinada a crear els múltiples
@@ -165,3 +164,29 @@ Alguna de la informació pot ser tècnica.
165
 
166
  Gràcies per utilitzar la nostra aplicació! Esperem que aquesta guia t'ajudi a navegar i utilitzar totes les funcions de manera efectiva.
167
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  </script>
12
  """
13
 
14
+ docu_eng = """
15
  ## User Guide
16
 
17
  This application is intended to create the multiple
 
89
  Thank you for using our application! We hope this guide helps you navigate and use all the features effectively.
90
  """
91
 
92
+ docu_cat = """
 
93
  ## Guia d'Usuari
94
 
95
  Aquesta aplicació està destinada a crear els múltiples
 
164
 
165
  Gràcies per utilitzar la nostra aplicació! Esperem que aquesta guia t'ajudi a navegar i utilitzar totes les funcions de manera efectiva.
166
  """
167
+
168
+ css_image_aspect_ratio = """
169
+ #image-container {
170
+ position: relative;
171
+ width: min(1280px, 100%);
172
+ height: 100% !important;
173
+ border-style: dashed;
174
+ overflow: hidden;
175
+ min-width: min(160px, 100%);
176
+ }
177
+
178
+ #image-container > div.wrap {
179
+ position: absolute;
180
+ top: 0;
181
+ left: 0;
182
+ width: 100%;
183
+ height: 100%;
184
+ }
185
+
186
+ #image-container video {
187
+ width: 100%;
188
+ height: auto;
189
+ object-fit: cover;
190
+ }
191
+ """
192
+