baudm commited on
Commit
8ff3b16
1 Parent(s): 1309224

UI improvements

Browse files

- Use a tabbed interface for upload/canvas image
- Hide detailed output by default. Allow toggling.

Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -71,27 +71,28 @@ def main():
71
 
72
  To use this interactive demo for PARSeq and reproduced models:
73
  1. Select which model you want to use.
74
- 2. Upload your own image, choose from the examples below, or draw on the canvas.
75
- 3. Click **Read Image** or **Read Drawing**.
76
 
77
  *NOTE*: None of these models were trained on handwritten text datasets.
78
  """)
79
  model_name = gr.Radio(app.models, value=app.models[0], label='The STR model to use')
80
- with gr.Row():
81
- with gr.Column():
82
  image_upload = gr.Image(type='pil', source='upload', label='Image')
83
- read_upload = gr.Button('Read Image')
84
- with gr.Column():
85
- image_canvas = gr.Image(type='pil', source='canvas', label='Drawing')
86
- read_canvas = gr.Button('Read Drawing')
 
87
 
88
  output = gr.Textbox(max_lines=1, label='Model output')
89
- raw_output = gr.Dataframe(row_count=2, col_count=0, label='Raw output with confidence values (interval: [0, 1], [B]: BOS or BLANK token, [E]: EOS token)')
90
-
91
- gr.Examples(glob.glob('demo_images/*.*'), inputs=image_upload)
92
 
93
  read_upload.click(app, inputs=[model_name, image_upload], outputs=[output, raw_output])
94
  read_canvas.click(app, inputs=[model_name, image_canvas], outputs=[output, raw_output])
 
95
 
96
  demo.launch()
97
 
 
71
 
72
  To use this interactive demo for PARSeq and reproduced models:
73
  1. Select which model you want to use.
74
+ 2. Upload your own cropped image (or select from the given examples), or sketch on the canvas.
75
+ 3. Click **Read Text**.
76
 
77
  *NOTE*: None of these models were trained on handwritten text datasets.
78
  """)
79
  model_name = gr.Radio(app.models, value=app.models[0], label='The STR model to use')
80
+ with gr.Tabs():
81
+ with gr.TabItem('Image Upload'):
82
  image_upload = gr.Image(type='pil', source='upload', label='Image')
83
+ gr.Examples(glob.glob('demo_images/*.*'), inputs=image_upload)
84
+ read_upload = gr.Button('Read Text')
85
+ with gr.TabItem('Canvas Sketch'):
86
+ image_canvas = gr.Image(type='pil', source='canvas', label='Sketch')
87
+ read_canvas = gr.Button('Read Text')
88
 
89
  output = gr.Textbox(max_lines=1, label='Model output')
90
+ adv_output = gr.Checkbox(label='Show detailed output')
91
+ raw_output = gr.Dataframe(row_count=2, col_count=0, label='Raw output with confidence values ([0, 1] interval; [B] - BLANK token; [E] - EOS token)', visible=False)
 
92
 
93
  read_upload.click(app, inputs=[model_name, image_upload], outputs=[output, raw_output])
94
  read_canvas.click(app, inputs=[model_name, image_canvas], outputs=[output, raw_output])
95
+ adv_output.change(lambda x: gr.update(visible=x), inputs=adv_output, outputs=raw_output)
96
 
97
  demo.launch()
98