multimodalart HF staff commited on
Commit
2dbfae1
1 Parent(s): 2f7e080

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -87,30 +87,31 @@ def load_captioning(uploaded_images, option):
87
  updates = []
88
  if len(uploaded_images) <= 1:
89
  raise gr.Error(
90
- "Error: please upload at least 2 images to train your model (the ideal number with default settings is between 4-30)"
91
  )
92
- if len(uploaded_images) > MAX_IMAGES:
93
  raise gr.Error(
94
- f"Error: for now, only {MAX_IMAGES} or less images are allowed for training"
95
  )
96
- # Update for the captioning_area
97
- for _ in range(3):
98
- updates.append(gr.update(visible=True))
99
- # Update visibility and image for each captioning row and image
100
- for i in range(1, MAX_IMAGES + 1):
101
- # Determine if the current row and image should be visible
102
- visible = i <= len(uploaded_images)
103
-
104
- # Update visibility of the captioning row
105
- updates.append(gr.update(visible=visible))
106
-
107
- # Update for image component - display image if available, otherwise hide
108
- image_value = uploaded_images[i - 1] if visible else None
109
- updates.append(gr.update(value=image_value, visible=visible))
110
-
111
- text_value = option if visible else None
112
- updates.append(gr.update(value=text_value, visible=visible))
113
- return updates
 
114
 
115
  def check_removed_and_restart(images):
116
  visible = bool(images)
 
87
  updates = []
88
  if len(uploaded_images) <= 1:
89
  raise gr.Error(
90
+ "Please upload at least 2 images to train your model (the ideal number with default settings is between 4-30)"
91
  )
92
+ elif len(uploaded_images) > MAX_IMAGES:
93
  raise gr.Error(
94
+ f"For now, only {MAX_IMAGES} or less images are allowed for training"
95
  )
96
+ else:
97
+ # Update for the captioning_area
98
+ for _ in range(3):
99
+ updates.append(gr.update(visible=True))
100
+ # Update visibility and image for each captioning row and image
101
+ for i in range(1, MAX_IMAGES + 1):
102
+ # Determine if the current row and image should be visible
103
+ visible = i <= len(uploaded_images)
104
+
105
+ # Update visibility of the captioning row
106
+ updates.append(gr.update(visible=visible))
107
+
108
+ # Update for image component - display image if available, otherwise hide
109
+ image_value = uploaded_images[i - 1] if visible else None
110
+ updates.append(gr.update(value=image_value, visible=visible))
111
+
112
+ text_value = option if visible else None
113
+ updates.append(gr.update(value=text_value, visible=visible))
114
+ return updates
115
 
116
  def check_removed_and_restart(images):
117
  visible = bool(images)