SWHL commited on
Commit
6dbbae0
1 Parent(s): ff4d99d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -92,9 +92,7 @@ if __name__ == "__main__":
92
  unsafe_allow_html=True,
93
  )
94
 
95
- col1, col2 = st.columns([0.5, 0.5])
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.sidebar.number_input(
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
- with col1:
122
- canvas_result = st_canvas(
123
- fill_color="rgba(255, 165, 0, 0.1)",
124
- stroke_width=1,
125
- stroke_color="#FFAA00",
126
- background_color="#FFF",
127
- background_image=pil_image,
128
- update_streamlit=True,
129
- height=get_image_size(pil_image)[0],
130
- width=get_image_size(pil_image)[1],
131
- drawing_mode="rect",
132
- point_display_radius=0,
133
- key=canvas_hash,
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
- with col2:
149
- bbox_nums = len(bbox_list)
150
- for i, bbox in enumerate(bbox_list):
151
- input_img = pil_image.crop(bbox)
152
- rec_res, elapse = model(np.array(input_img))
153
- st.markdown(f"#### {i + 1} (cost: {elapse:.3f}s)")
154
- st.latex(rec_res)
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)