wjm55 commited on
Commit
44b7045
·
1 Parent(s): 3057e7a

fixed download functions

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -10,6 +10,8 @@ import numpy as np
10
  import os
11
  from gliner import GLiNER
12
  import json
 
 
13
 
14
  # Initialize GLiNER model
15
  gliner_model = GLiNER.from_pretrained("knowledgator/modern-gliner-bi-large-v1.0")
@@ -251,6 +253,7 @@ with gr.Blocks(css=css) as demo:
251
  with gr.Row():
252
  filename = gr.Textbox(label="Save filename (without extension)", placeholder="Enter filename to save")
253
  download_btn = gr.Button("Download Image & Text", elem_classes="submit-btn")
 
254
 
255
  def create_zip(image, text_data, fname):
256
  if not isinstance(image, (Image.Image, np.ndarray)) or not text_data or not fname:
@@ -304,5 +307,12 @@ with gr.Blocks(css=css) as demo:
304
 
305
  return zip_path
306
 
 
 
 
 
 
 
 
307
  demo.queue(api_open=False)
308
  demo.launch(debug=True)
 
10
  import os
11
  from gliner import GLiNER
12
  import json
13
+ import tempfile
14
+ import zipfile
15
 
16
  # Initialize GLiNER model
17
  gliner_model = GLiNER.from_pretrained("knowledgator/modern-gliner-bi-large-v1.0")
 
253
  with gr.Row():
254
  filename = gr.Textbox(label="Save filename (without extension)", placeholder="Enter filename to save")
255
  download_btn = gr.Button("Download Image & Text", elem_classes="submit-btn")
256
+ download_output = gr.File(label="Download")
257
 
258
  def create_zip(image, text_data, fname):
259
  if not isinstance(image, (Image.Image, np.ndarray)) or not text_data or not fname:
 
307
 
308
  return zip_path
309
 
310
+ # Add the click handler for the download button
311
+ download_btn.click(
312
+ create_zip,
313
+ inputs=[input_img, output_text, filename],
314
+ outputs=[download_output]
315
+ )
316
+
317
  demo.queue(api_open=False)
318
  demo.launch(debug=True)