mrrtmob commited on
Commit
35ff054
·
verified ·
1 Parent(s): ce65b20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -4
app.py CHANGED
@@ -181,7 +181,9 @@ with gr.Blocks(title="Kiri OCR - Streaming Demo", css=css, theme=gr.themes.Soft(
181
  sources=["upload", "clipboard", "webcam"]
182
  )
183
 
184
- doc_btn = gr.Button("⚡ Stream Text", variant="primary")
 
 
185
 
186
  with gr.Column(scale=1):
187
  # Annotated image updates in real-time
@@ -205,7 +207,9 @@ with gr.Blocks(title="Kiri OCR - Streaming Demo", css=css, theme=gr.themes.Soft(
205
  type="pil",
206
  sources=["upload", "clipboard"]
207
  )
208
- line_btn = gr.Button("⚡ Stream Recognize", variant="primary")
 
 
209
 
210
  with gr.Column(scale=1):
211
  line_output_text = gr.Textbox(
@@ -215,21 +219,54 @@ with gr.Blocks(title="Kiri OCR - Streaming Demo", css=css, theme=gr.themes.Soft(
215
  )
216
 
217
 
218
- stop_btn = gr.Button("⏹️ Stop Generation", variant="secondary")
 
 
219
 
 
 
 
220
  doc_event = doc_btn.click(
 
 
 
221
  fn=process_document_stream,
222
  inputs=[doc_input],
223
  outputs=[doc_output_img, doc_output_text]
 
 
 
 
 
 
 
 
 
224
  )
225
 
 
 
 
 
 
 
226
  line_event = line_btn.click(
 
 
 
227
  fn=recognize_line_stream,
228
  inputs=line_input,
229
  outputs=line_output_text
 
 
 
230
  )
231
 
232
- stop_btn.click(fn=None, inputs=None, outputs=None, cancels=[doc_event, line_event])
 
 
 
 
233
 
234
  gr.Markdown(
235
  """
 
181
  sources=["upload", "clipboard", "webcam"]
182
  )
183
 
184
+ with gr.Row():
185
+ doc_btn = gr.Button("⚡ Stream Text", variant="primary")
186
+ doc_stop = gr.Button("⏹️ Stop", variant="secondary", visible=False)
187
 
188
  with gr.Column(scale=1):
189
  # Annotated image updates in real-time
 
207
  type="pil",
208
  sources=["upload", "clipboard"]
209
  )
210
+ with gr.Row():
211
+ line_btn = gr.Button("⚡ Stream Recognize", variant="primary")
212
+ line_stop = gr.Button("⏹️ Stop", variant="secondary", visible=False)
213
 
214
  with gr.Column(scale=1):
215
  line_output_text = gr.Textbox(
 
219
  )
220
 
221
 
222
+ # Toggle buttons visibility
223
+ def toggle_doc_buttons():
224
+ return gr.update(visible=False), gr.update(visible=True)
225
 
226
+ def reset_doc_buttons():
227
+ return gr.update(visible=True), gr.update(visible=False)
228
+
229
  doc_event = doc_btn.click(
230
+ fn=toggle_doc_buttons,
231
+ outputs=[doc_btn, doc_stop]
232
+ ).then(
233
  fn=process_document_stream,
234
  inputs=[doc_input],
235
  outputs=[doc_output_img, doc_output_text]
236
+ ).then(
237
+ fn=reset_doc_buttons,
238
+ outputs=[doc_btn, doc_stop]
239
+ )
240
+
241
+ doc_stop.click(
242
+ fn=reset_doc_buttons,
243
+ outputs=[doc_btn, doc_stop],
244
+ cancels=[doc_event]
245
  )
246
 
247
+ def toggle_line_buttons():
248
+ return gr.update(visible=False), gr.update(visible=True)
249
+
250
+ def reset_line_buttons():
251
+ return gr.update(visible=True), gr.update(visible=False)
252
+
253
  line_event = line_btn.click(
254
+ fn=toggle_line_buttons,
255
+ outputs=[line_btn, line_stop]
256
+ ).then(
257
  fn=recognize_line_stream,
258
  inputs=line_input,
259
  outputs=line_output_text
260
+ ).then(
261
+ fn=reset_line_buttons,
262
+ outputs=[line_btn, line_stop]
263
  )
264
 
265
+ line_stop.click(
266
+ fn=reset_line_buttons,
267
+ outputs=[line_btn, line_stop],
268
+ cancels=[line_event]
269
+ )
270
 
271
  gr.Markdown(
272
  """