to-be commited on
Commit
be4a233
1 Parent(s): ee93a12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -16,6 +16,8 @@ model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
  model.to(device)
18
 
 
 
19
  def process_document(image):
20
  img2.update(visible=True)
21
  gr.update()
@@ -101,7 +103,19 @@ with gr.Blocks(css=css) as demo:
101
  imgout = gr.Image(label='Uploaded document:',elem_id="inp")
102
  with gr.Column(scale=1):
103
  jsonout = gr.JSON(label='Extracted information:')
104
-
105
  btn.click(fn=process_document, inputs=inp, outputs=[jsonout,imgout])
106
 
107
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
  model.to(device)
18
 
19
+ state = "start_or_clear"
20
+
21
  def process_document(image):
22
  img2.update(visible=True)
23
  gr.update()
 
103
  imgout = gr.Image(label='Uploaded document:',elem_id="inp")
104
  with gr.Column(scale=1):
105
  jsonout = gr.JSON(label='Extracted information:')
106
+ inp.change(fn=update_status,inputs=inp,outputs=[img2,img3])
107
  btn.click(fn=process_document, inputs=inp, outputs=[jsonout,imgout])
108
 
109
+ demo.launch()
110
+ def update_status(inp):
111
+ if state == "start_or_clear":
112
+ state = 'processing' #current state becomes
113
+ return (gr.update(value="snowangel.gif",visible=True),gr.update(value="snowangel.gif",visible=True))
114
+ elif state == "processing":
115
+ state = 'finished_processing' #current state becomes
116
+ return (gr.update(value="",visible=False),gr.update(value="",visible=False))
117
+ elif state == "finished_processing":
118
+ state = 'processing' #current state becomes
119
+ return (gr.update(value="snowangel.gif",visible=True),gr.update(value="snowangel.gif",visible=True))
120
+
121
+