Spaces:
Paused
Paused
backup
Browse files
app.py
CHANGED
@@ -151,10 +151,14 @@ def load_question_data(question_id):
|
|
151 |
|
152 |
def load_post_image(post_id):
|
153 |
if not post_id:
|
154 |
-
return [
|
|
|
|
|
155 |
|
156 |
idx = POST_ID_TO_ID_MAP[post_id]
|
157 |
source_image = VALID_DATASET[idx]["image"]
|
|
|
|
|
158 |
|
159 |
# Load existing responses if any
|
160 |
post_folder = os.path.join("./data", str(post_id))
|
@@ -175,15 +179,15 @@ def load_post_image(post_id):
|
|
175 |
responses[idx] = (
|
176 |
image_path,
|
177 |
response["answer_text"],
|
178 |
-
response.get("notes", ""),
|
179 |
)
|
180 |
|
181 |
# Flatten responses for output
|
182 |
flat_responses = [item for triplet in responses for item in triplet]
|
183 |
-
return [source_image] + flat_responses
|
184 |
|
185 |
-
# If no existing responses, return source image and empty responses
|
186 |
-
return [source_image] + [None] * 30
|
187 |
|
188 |
|
189 |
def generate_json_files(source_image, responses, post_id):
|
@@ -255,21 +259,28 @@ with gr.Blocks() as demo:
|
|
255 |
gr.Markdown("# Image Response Collector")
|
256 |
|
257 |
# Source image selection at the top
|
258 |
-
with gr.
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
# Responses in tabs
|
268 |
with gr.Tabs() as response_tabs:
|
269 |
responses = []
|
270 |
for i in range(10):
|
271 |
with gr.Tab(f"Response {i+1}"):
|
272 |
-
img = gr.Image(
|
|
|
|
|
273 |
txt = gr.Textbox(label=f"Model Name {i+1}", lines=2)
|
274 |
notes = gr.Textbox(label=f"Miscellaneous Notes {i+1}", lines=3)
|
275 |
responses.append((img, txt, notes))
|
@@ -278,7 +289,9 @@ with gr.Blocks() as demo:
|
|
278 |
submit_btn = gr.Button("Submit All Responses")
|
279 |
clear_btn = gr.Button("Clear Form")
|
280 |
|
281 |
-
def submit_responses(
|
|
|
|
|
282 |
if not source_img:
|
283 |
gr.Warning("Please select a source image first!")
|
284 |
return
|
@@ -309,23 +322,29 @@ with gr.Blocks() as demo:
|
|
309 |
|
310 |
def clear_form():
|
311 |
outputs = [None] * (
|
312 |
-
1 + 30
|
313 |
-
) #
|
314 |
return outputs
|
315 |
|
316 |
# Connect components
|
317 |
post_id_dropdown.change(
|
318 |
fn=load_post_image,
|
319 |
inputs=[post_id_dropdown],
|
320 |
-
outputs=[source_image
|
|
|
321 |
)
|
322 |
|
323 |
-
submit_inputs = [
|
324 |
-
|
325 |
-
|
|
|
|
|
|
|
326 |
submit_btn.click(fn=submit_responses, inputs=submit_inputs)
|
327 |
|
328 |
-
clear_outputs = [source_image] + [
|
|
|
|
|
329 |
clear_btn.click(fn=clear_form, outputs=clear_outputs)
|
330 |
|
331 |
|
|
|
151 |
|
152 |
def load_post_image(post_id):
|
153 |
if not post_id:
|
154 |
+
return [
|
155 |
+
None
|
156 |
+
] * 33 # source image + instruction + simplified_instruction + 10 triplets
|
157 |
|
158 |
idx = POST_ID_TO_ID_MAP[post_id]
|
159 |
source_image = VALID_DATASET[idx]["image"]
|
160 |
+
instruction = VALID_DATASET[idx]["instruction"]
|
161 |
+
simplified_instruction = VALID_DATASET[idx]["simplified_instruction"]
|
162 |
|
163 |
# Load existing responses if any
|
164 |
post_folder = os.path.join("./data", str(post_id))
|
|
|
179 |
responses[idx] = (
|
180 |
image_path,
|
181 |
response["answer_text"],
|
182 |
+
response.get("notes", ""),
|
183 |
)
|
184 |
|
185 |
# Flatten responses for output
|
186 |
flat_responses = [item for triplet in responses for item in triplet]
|
187 |
+
return [source_image, instruction, simplified_instruction] + flat_responses
|
188 |
|
189 |
+
# If no existing responses, return source image, instructions and empty responses
|
190 |
+
return [source_image, instruction, simplified_instruction] + [None] * 30
|
191 |
|
192 |
|
193 |
def generate_json_files(source_image, responses, post_id):
|
|
|
259 |
gr.Markdown("# Image Response Collector")
|
260 |
|
261 |
# Source image selection at the top
|
262 |
+
with gr.Row():
|
263 |
+
with gr.Column():
|
264 |
+
post_id_dropdown = gr.Dropdown(
|
265 |
+
label="Select Post ID to Load Image",
|
266 |
+
choices=VALID_DATASET_POST_IDS,
|
267 |
+
type="value",
|
268 |
+
allow_custom_value=False,
|
269 |
+
)
|
270 |
+
instruction_text = gr.Textbox(label="Instruction", interactive=False)
|
271 |
+
simplified_instruction_text = gr.Textbox(
|
272 |
+
label="Simplified Instruction", interactive=False
|
273 |
+
)
|
274 |
+
source_image = gr.Image(label="Source Image", type="filepath", height=300)
|
275 |
|
276 |
# Responses in tabs
|
277 |
with gr.Tabs() as response_tabs:
|
278 |
responses = []
|
279 |
for i in range(10):
|
280 |
with gr.Tab(f"Response {i+1}"):
|
281 |
+
img = gr.Image(
|
282 |
+
label=f"Response Image {i+1}", type="filepath", height=300
|
283 |
+
)
|
284 |
txt = gr.Textbox(label=f"Model Name {i+1}", lines=2)
|
285 |
notes = gr.Textbox(label=f"Miscellaneous Notes {i+1}", lines=3)
|
286 |
responses.append((img, txt, notes))
|
|
|
289 |
submit_btn = gr.Button("Submit All Responses")
|
290 |
clear_btn = gr.Button("Clear Form")
|
291 |
|
292 |
+
def submit_responses(
|
293 |
+
source_img, post_id, instruction, simplified_instruction, *response_data
|
294 |
+
):
|
295 |
if not source_img:
|
296 |
gr.Warning("Please select a source image first!")
|
297 |
return
|
|
|
322 |
|
323 |
def clear_form():
|
324 |
outputs = [None] * (
|
325 |
+
1 + 2 + 30
|
326 |
+
) # source image + 2 instruction fields + 10 triplets
|
327 |
return outputs
|
328 |
|
329 |
# Connect components
|
330 |
post_id_dropdown.change(
|
331 |
fn=load_post_image,
|
332 |
inputs=[post_id_dropdown],
|
333 |
+
outputs=[source_image, instruction_text, simplified_instruction_text]
|
334 |
+
+ [comp for triplet in responses for comp in triplet],
|
335 |
)
|
336 |
|
337 |
+
submit_inputs = [
|
338 |
+
source_image,
|
339 |
+
post_id_dropdown,
|
340 |
+
instruction_text,
|
341 |
+
simplified_instruction_text,
|
342 |
+
] + [comp for triplet in responses for comp in triplet]
|
343 |
submit_btn.click(fn=submit_responses, inputs=submit_inputs)
|
344 |
|
345 |
+
clear_outputs = [source_image, instruction_text, simplified_instruction_text] + [
|
346 |
+
comp for triplet in responses for comp in triplet
|
347 |
+
]
|
348 |
clear_btn.click(fn=clear_form, outputs=clear_outputs)
|
349 |
|
350 |
|