Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,9 +92,7 @@ if __name__ == "__main__":
|
|
| 92 |
unsafe_allow_html=True,
|
| 93 |
)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
in_file = st.sidebar.file_uploader(
|
| 98 |
"PDF file or image:", type=["pdf", "png", "jpg", "jpeg", "gif", "webp"]
|
| 99 |
)
|
| 100 |
|
|
@@ -104,7 +102,7 @@ if __name__ == "__main__":
|
|
| 104 |
filetype = in_file.type
|
| 105 |
if "pdf" in filetype:
|
| 106 |
page_count = page_count(in_file)
|
| 107 |
-
page_number = st.
|
| 108 |
f"Page number out of {page_count}:",
|
| 109 |
min_value=1,
|
| 110 |
value=1,
|
|
@@ -118,20 +116,19 @@ if __name__ == "__main__":
|
|
| 118 |
canvas_hash = get_canvas_hash(pil_image) if pil_image else "canvas"
|
| 119 |
|
| 120 |
model = load_model_cached()
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
)
|
| 135 |
|
| 136 |
if canvas_result.json_data is not None:
|
| 137 |
objects = pd.json_normalize(canvas_result.json_data["objects"])
|
|
@@ -145,11 +142,10 @@ if __name__ == "__main__":
|
|
| 145 |
bbox_list = boxes[["left", "top", "right", "bottom"]].values.tolist()
|
| 146 |
|
| 147 |
if bbox_list:
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
st.code(rec_res)
|
|
|
|
| 92 |
unsafe_allow_html=True,
|
| 93 |
)
|
| 94 |
|
| 95 |
+
in_file = st.file_uploader(
|
|
|
|
|
|
|
| 96 |
"PDF file or image:", type=["pdf", "png", "jpg", "jpeg", "gif", "webp"]
|
| 97 |
)
|
| 98 |
|
|
|
|
| 102 |
filetype = in_file.type
|
| 103 |
if "pdf" in filetype:
|
| 104 |
page_count = page_count(in_file)
|
| 105 |
+
page_number = st.number_input(
|
| 106 |
f"Page number out of {page_count}:",
|
| 107 |
min_value=1,
|
| 108 |
value=1,
|
|
|
|
| 116 |
canvas_hash = get_canvas_hash(pil_image) if pil_image else "canvas"
|
| 117 |
|
| 118 |
model = load_model_cached()
|
| 119 |
+
canvas_result = st_canvas(
|
| 120 |
+
fill_color="rgba(255, 165, 0, 0.1)",
|
| 121 |
+
stroke_width=1,
|
| 122 |
+
stroke_color="#FFAA00",
|
| 123 |
+
background_color="#FFF",
|
| 124 |
+
background_image=pil_image,
|
| 125 |
+
update_streamlit=True,
|
| 126 |
+
height=get_image_size(pil_image)[0],
|
| 127 |
+
width=get_image_size(pil_image)[1],
|
| 128 |
+
drawing_mode="rect",
|
| 129 |
+
point_display_radius=0,
|
| 130 |
+
key=canvas_hash,
|
| 131 |
+
)
|
|
|
|
| 132 |
|
| 133 |
if canvas_result.json_data is not None:
|
| 134 |
objects = pd.json_normalize(canvas_result.json_data["objects"])
|
|
|
|
| 142 |
bbox_list = boxes[["left", "top", "right", "bottom"]].values.tolist()
|
| 143 |
|
| 144 |
if bbox_list:
|
| 145 |
+
bbox_nums = len(bbox_list)
|
| 146 |
+
for i, bbox in enumerate(bbox_list):
|
| 147 |
+
input_img = pil_image.crop(bbox)
|
| 148 |
+
rec_res, elapse = model(np.array(input_img))
|
| 149 |
+
st.markdown(f"#### {i + 1}. (cost: {elapse:.3f}s)")
|
| 150 |
+
st.latex(rec_res)
|
| 151 |
+
st.code(rec_res)
|
|
|