Gabriel commited on
Commit
c3b1fcc
1 Parent(s): d543428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -16,7 +16,14 @@ def get_image_ids(batch_id: str) -> list[str]:
16
  response = requests.get(f"{IIIF_URL}/arkis!{batch_id}/manifest")
17
  response.raise_for_status()
18
  response = response.json()
19
- image_ids = [item["id"].split("!")[1][:14] for item in response["items"]]
 
 
 
 
 
 
 
20
  logging.info(f"Found {len(image_ids)} images in batch {batch_id}")
21
  return image_ids
22
 
@@ -52,6 +59,8 @@ def download_image_by_image_id(image_id: str):
52
  def download_batch_images(batch_id: str, workers: int = 2, progress=None):
53
  logging.info(f"Starting download for batch {batch_id}")
54
  image_ids = get_image_ids(batch_id)
 
 
55
  total_images = len(image_ids)
56
 
57
  if progress:
@@ -89,10 +98,10 @@ def gradio_interface(batch_id_input, progress=gr.Progress()):
89
  batch_id = batch_id_input.strip()
90
  try:
91
  zip_file = download_batch_images(batch_id, progress=progress)
92
- return zip_file # Return the zip file for download
93
  except Exception as e:
94
  logging.error(f"Error processing batch: {e}")
95
- return str(e)
96
 
97
  with gr.Blocks() as app:
98
  gr.Markdown("# Batch Image Downloader")
@@ -103,11 +112,12 @@ with gr.Blocks() as app:
103
  download_button = gr.Button("Download Images")
104
  with gr.Column():
105
  output_file = gr.File(label="Download Zip File")
 
106
 
107
  download_button.click(
108
  gradio_interface,
109
  inputs=[batch_id_input],
110
- outputs=[output_file]
111
  )
112
 
113
  app.queue()
 
16
  response = requests.get(f"{IIIF_URL}/arkis!{batch_id}/manifest")
17
  response.raise_for_status()
18
  response = response.json()
19
+ image_ids = []
20
+ for item in response.get("items", []):
21
+ id_parts = item["id"].split("!")
22
+ if len(id_parts) > 1:
23
+ image_id = id_parts[1][:14]
24
+ image_ids.append(image_id)
25
+ else:
26
+ logging.warning(f"Unexpected id format: {item['id']}")
27
  logging.info(f"Found {len(image_ids)} images in batch {batch_id}")
28
  return image_ids
29
 
 
59
  def download_batch_images(batch_id: str, workers: int = 2, progress=None):
60
  logging.info(f"Starting download for batch {batch_id}")
61
  image_ids = get_image_ids(batch_id)
62
+ if not image_ids:
63
+ raise ValueError("No images found to download.")
64
  total_images = len(image_ids)
65
 
66
  if progress:
 
98
  batch_id = batch_id_input.strip()
99
  try:
100
  zip_file = download_batch_images(batch_id, progress=progress)
101
+ return zip_file, "" # No error message
102
  except Exception as e:
103
  logging.error(f"Error processing batch: {e}")
104
+ return None, f"Error: {str(e)}" # Return error message
105
 
106
  with gr.Blocks() as app:
107
  gr.Markdown("# Batch Image Downloader")
 
112
  download_button = gr.Button("Download Images")
113
  with gr.Column():
114
  output_file = gr.File(label="Download Zip File")
115
+ error_message = gr.Textbox(label="Error Message", interactive=False)
116
 
117
  download_button.click(
118
  gradio_interface,
119
  inputs=[batch_id_input],
120
+ outputs=[output_file, error_message]
121
  )
122
 
123
  app.queue()