Ankur Goyal commited on
Commit
15fad86
1 Parent(s): 8393858

Hide the outputs by default

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -89,17 +89,29 @@ def process_path(path):
89
  if path:
90
  try:
91
  document = load_document(path)
92
- return document, document.preview, None
 
 
 
 
93
  except Exception:
94
  pass
95
- return None, None, None
 
 
 
 
96
 
97
 
98
  def process_upload(file):
99
  if file:
100
  return process_path(file.name)
101
  else:
102
- return None, None, None
 
 
 
 
103
 
104
 
105
  colors = ["#64A087", "green", "black"]
@@ -126,7 +138,9 @@ def process_question(question, document, model=list(CHECKPOINTS.keys())[0]):
126
  )
127
  draw.rectangle(((x1, y1), (x2, y2)), fill=(0, 255, 0, int(0.4 * 255)))
128
 
129
- return image, predictions
 
 
130
 
131
 
132
  def load_example_document(img, question, model):
@@ -183,15 +197,21 @@ with gr.Blocks(css=CSS) as demo:
183
  submit_button = gr.Button("Submit", variant="primary", elem_id="submit-button")
184
 
185
  with gr.Row():
186
- image = gr.Image(visible=True)
187
  with gr.Column():
188
- output = gr.JSON(label="Output")
189
 
190
  clear_button.click(
191
- lambda _: (None, None, None, None),
 
 
 
 
 
192
  inputs=clear_button,
193
  outputs=[image, document, question, output],
194
  )
 
195
  upload.change(fn=process_upload, inputs=[upload], outputs=[document, image, output])
196
  url.change(fn=process_path, inputs=[url], outputs=[document, image, output])
197
 
 
89
  if path:
90
  try:
91
  document = load_document(path)
92
+ return (
93
+ document,
94
+ gr.update(visible=True, value=document.preview),
95
+ gr.update(visible=False, value=None),
96
+ )
97
  except Exception:
98
  pass
99
+ return (
100
+ None,
101
+ gr.update(visible=False, value=None),
102
+ gr.update(visible=False, value=None),
103
+ )
104
 
105
 
106
  def process_upload(file):
107
  if file:
108
  return process_path(file.name)
109
  else:
110
+ return (
111
+ None,
112
+ gr.update(visible=False, value=None),
113
+ gr.update(visible=False, value=None),
114
+ )
115
 
116
 
117
  colors = ["#64A087", "green", "black"]
 
138
  )
139
  draw.rectangle(((x1, y1), (x2, y2)), fill=(0, 255, 0, int(0.4 * 255)))
140
 
141
+ return gr.update(visible=True, value=image), gr.update(
142
+ visible=True, value=predictions
143
+ )
144
 
145
 
146
  def load_example_document(img, question, model):
 
197
  submit_button = gr.Button("Submit", variant="primary", elem_id="submit-button")
198
 
199
  with gr.Row():
200
+ image = gr.Image(visible=False)
201
  with gr.Column():
202
+ output = gr.JSON(label="Output", visible=False)
203
 
204
  clear_button.click(
205
+ lambda _: (
206
+ gr.update(visible=False, value=None),
207
+ None,
208
+ None,
209
+ gr.update(visible=False, value=None),
210
+ ),
211
  inputs=clear_button,
212
  outputs=[image, document, question, output],
213
  )
214
+
215
  upload.change(fn=process_upload, inputs=[upload], outputs=[document, image, output])
216
  url.change(fn=process_path, inputs=[url], outputs=[document, image, output])
217