Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
|
@@ -151,23 +151,25 @@ def generate(
|
|
| 151 |
image_start_index_list=image_start_index_list,
|
| 152 |
image_nums=image_nums,
|
| 153 |
)
|
|
|
|
| 154 |
boxes = outputs["boxes"]
|
| 155 |
scores = outputs["scores"]
|
| 156 |
if len(scores) > 0:
|
| 157 |
box = boxes[scores.argmax()]
|
| 158 |
-
else:
|
| 159 |
-
iou = 0.0
|
| 160 |
-
# tqdm.write(f"output: {tokenizer.batch_decode(outputs)}")
|
| 161 |
-
tqdm.write(f"no output for: {uniq_id}, {image_id}, {text}")
|
| 162 |
print(f"{box}")
|
| 163 |
|
| 164 |
-
|
| 165 |
-
gen_text = tokenizer.batch_decode(outputs)
|
| 166 |
if idx == 1:
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
elif idx == 2:
|
|
|
|
| 169 |
return (f"Question: {text.strip()} Answer: {gen_text}")
|
| 170 |
else:
|
|
|
|
| 171 |
return (f"Output:{gen_text}")
|
| 172 |
|
| 173 |
|
|
|
|
| 151 |
image_start_index_list=image_start_index_list,
|
| 152 |
image_nums=image_nums,
|
| 153 |
)
|
| 154 |
+
|
| 155 |
boxes = outputs["boxes"]
|
| 156 |
scores = outputs["scores"]
|
| 157 |
if len(scores) > 0:
|
| 158 |
box = boxes[scores.argmax()]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
print(f"{box}")
|
| 160 |
|
|
|
|
|
|
|
| 161 |
if idx == 1:
|
| 162 |
+
open_cv_image = np.array(image)
|
| 163 |
+
# Convert RGB to BGR
|
| 164 |
+
open_cv_image = open_cv_image[:, :, ::-1].copy()
|
| 165 |
+
open_cv_image = cv2.rectangle(open_cv_image, box[:2].astype(int), box[2:].astype(int), (255, 0, 0), 2)
|
| 166 |
+
out_image = Image.fromarray(cv2.cvtColor(open_cv_image, cv2.COLOR_BGR2RGB))
|
| 167 |
+
return f"Output:{box}", out_image
|
| 168 |
elif idx == 2:
|
| 169 |
+
gen_text = tokenizer.batch_decode(outputs)
|
| 170 |
return (f"Question: {text.strip()} Answer: {gen_text}")
|
| 171 |
else:
|
| 172 |
+
gen_text = tokenizer.batch_decode(outputs)
|
| 173 |
return (f"Output:{gen_text}")
|
| 174 |
|
| 175 |
|