Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,11 +19,13 @@ def extract_coordinates(string):
|
|
19 |
numbers = list(map(int, numbers))
|
20 |
|
21 |
# Ensuring there are exactly 4 numbers
|
22 |
-
if len(numbers) != 4:
|
23 |
numbers = numbers[-4:]
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
return [x1, y1, x2, y2]
|
29 |
|
@@ -99,12 +101,15 @@ with col2:
|
|
99 |
|
100 |
# Get the coordinates from the output text and denormalize them
|
101 |
coordinates = extract_coordinates(output_text)
|
102 |
-
coordinates
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
108 |
elif testButton and selected_file == "None":
|
109 |
st.write("Please upload and select a document (/an image).")
|
110 |
|
|
|
19 |
numbers = list(map(int, numbers))
|
20 |
|
21 |
# Ensuring there are exactly 4 numbers
|
22 |
+
if len(numbers) >= 4: #if len(numbers) != 4:
|
23 |
numbers = numbers[-4:]
|
24 |
|
25 |
+
# Extracting coordinates
|
26 |
+
x1, y1, x2, y2 = numbers
|
27 |
+
else:
|
28 |
+
return []
|
29 |
|
30 |
return [x1, y1, x2, y2]
|
31 |
|
|
|
101 |
|
102 |
# Get the coordinates from the output text and denormalize them
|
103 |
coordinates = extract_coordinates(output_text)
|
104 |
+
if coordinates is not None:
|
105 |
+
coordinates = unnormalize_box(coordinates, unnormalized_image.width, unnormalized_image.height)
|
106 |
+
|
107 |
+
draw = ImageDraw.Draw(unnormalized_image)
|
108 |
+
draw.rectangle(coordinates, outline="red")
|
109 |
+
|
110 |
+
st.image(unnormalized_image, caption="Output Image")
|
111 |
+
else:
|
112 |
+
st.write("Cannot obtain Bounding Box coordinates: " + output_text)
|
113 |
elif testButton and selected_file == "None":
|
114 |
st.write("Please upload and select a document (/an image).")
|
115 |
|