Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,10 +36,6 @@ def unnormalize_box(box, image_width, image_height):
|
|
| 36 |
return [x1, y1, x2, y2]
|
| 37 |
|
| 38 |
|
| 39 |
-
# Get the coordinates from the output text and denormalize them
|
| 40 |
-
coordinates = extract_coordinates(output_text)
|
| 41 |
-
coordinates = unnormalize_box(coordinates, unnormalized_image.width, unnormalized_image.height)
|
| 42 |
-
|
| 43 |
processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=True)
|
| 44 |
model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
|
| 45 |
|
|
@@ -93,14 +89,21 @@ with col2:
|
|
| 93 |
st.write(output_text)
|
| 94 |
case "Layout Analysis":
|
| 95 |
output_text = processor.batch_decode(model_output, skip_special_tokens=False)[0]
|
|
|
|
| 96 |
mean = processor.image_processor.image_mean
|
| 97 |
std = processor.image_processor.image_std
|
| 98 |
unnormalized_image = (encoding.pixel_values.squeeze().numpy() * np.array(std)[:, None, None]) + np.array(mean)[:, None, None]
|
| 99 |
unnormalized_image = (unnormalized_image * 255).astype(np.uint8)
|
| 100 |
unnormalized_image = np.moveaxis(unnormalized_image, 0, -1)
|
| 101 |
unnormalized_image = Image.fromarray(unnormalized_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
draw = ImageDraw.Draw(unnormalized_image)
|
| 103 |
draw.rectangle(coordinates, outline="red")
|
|
|
|
| 104 |
st.image(unnormalized_image, caption="Output Image")
|
| 105 |
elif testButton and selected_file == "None":
|
| 106 |
st.write("Please upload and select a document (/an image).")
|
|
|
|
| 36 |
return [x1, y1, x2, y2]
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=True)
|
| 40 |
model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
|
| 41 |
|
|
|
|
| 89 |
st.write(output_text)
|
| 90 |
case "Layout Analysis":
|
| 91 |
output_text = processor.batch_decode(model_output, skip_special_tokens=False)[0]
|
| 92 |
+
|
| 93 |
mean = processor.image_processor.image_mean
|
| 94 |
std = processor.image_processor.image_std
|
| 95 |
unnormalized_image = (encoding.pixel_values.squeeze().numpy() * np.array(std)[:, None, None]) + np.array(mean)[:, None, None]
|
| 96 |
unnormalized_image = (unnormalized_image * 255).astype(np.uint8)
|
| 97 |
unnormalized_image = np.moveaxis(unnormalized_image, 0, -1)
|
| 98 |
unnormalized_image = Image.fromarray(unnormalized_image)
|
| 99 |
+
|
| 100 |
+
# Get the coordinates from the output text and denormalize them
|
| 101 |
+
coordinates = extract_coordinates(output_text)
|
| 102 |
+
coordinates = unnormalize_box(coordinates, unnormalized_image.width, unnormalized_image.height)
|
| 103 |
+
|
| 104 |
draw = ImageDraw.Draw(unnormalized_image)
|
| 105 |
draw.rectangle(coordinates, outline="red")
|
| 106 |
+
|
| 107 |
st.image(unnormalized_image, caption="Output Image")
|
| 108 |
elif testButton and selected_file == "None":
|
| 109 |
st.write("Please upload and select a document (/an image).")
|