Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -80,7 +80,11 @@ def inference(
|
|
80 |
|
81 |
det_model_path = str(Path("models") / "text_det" / text_det)
|
82 |
rec_model_path = str(Path("models") / "text_rec" / text_rec)
|
83 |
-
if
|
|
|
|
|
|
|
|
|
84 |
rec_image_shape = [3, 32, 320]
|
85 |
else:
|
86 |
rec_image_shape = [3, 48, 320]
|
@@ -104,7 +108,7 @@ def inference(
|
|
104 |
img, box_thresh=box_thresh, unclip_ratio=unclip_ratio, text_score=text_score
|
105 |
)
|
106 |
if not ocr_result or not infer_elapse:
|
107 |
-
return None, None, None
|
108 |
|
109 |
det_cost, cls_cost, rec_cost = infer_elapse
|
110 |
elapse = f"- `det cost`: {det_cost:.5f}\n - `cls cost`: {cls_cost:.5f}\n - `rec cost`: {rec_cost:.5f}"
|
@@ -178,17 +182,18 @@ if __name__ == "__main__":
|
|
178 |
]
|
179 |
select_rec = menu_rec.selectbox("Rec model:", rec_models)
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
192 |
|
193 |
if st.session_state["img"] is not None:
|
194 |
out_img, out_json, elapse = inference(select_det, select_rec)
|
|
|
80 |
|
81 |
det_model_path = str(Path("models") / "text_det" / text_det)
|
82 |
rec_model_path = str(Path("models") / "text_rec" / text_rec)
|
83 |
+
if (
|
84 |
+
"v2" in rec_model_path
|
85 |
+
or "korean" in rec_model_path
|
86 |
+
or "japan" in rec_model_path
|
87 |
+
):
|
88 |
rec_image_shape = [3, 32, 320]
|
89 |
else:
|
90 |
rec_image_shape = [3, 48, 320]
|
|
|
108 |
img, box_thresh=box_thresh, unclip_ratio=unclip_ratio, text_score=text_score
|
109 |
)
|
110 |
if not ocr_result or not infer_elapse:
|
111 |
+
return None, None, None
|
112 |
|
113 |
det_cost, cls_cost, rec_cost = infer_elapse
|
114 |
elapse = f"- `det cost`: {det_cost:.5f}\n - `cls cost`: {cls_cost:.5f}\n - `rec cost`: {rec_cost:.5f}"
|
|
|
182 |
]
|
183 |
select_rec = menu_rec.selectbox("Rec model:", rec_models)
|
184 |
|
185 |
+
with st.form("my-form", clear_on_submit=True):
|
186 |
+
img_file_buffer = st.file_uploader(
|
187 |
+
"Upload an image",
|
188 |
+
accept_multiple_files=False,
|
189 |
+
label_visibility="visible",
|
190 |
+
type=["png", "jpg", "jpeg", "bmp"],
|
191 |
+
)
|
192 |
+
submit = st.form_submit_button("Upload")
|
193 |
+
if submit and img_file_buffer is not None:
|
194 |
+
image = Image.open(img_file_buffer)
|
195 |
+
img = np.array(image)
|
196 |
+
st.session_state["img"] = img
|
197 |
|
198 |
if st.session_state["img"] is not None:
|
199 |
out_img, out_json, elapse = inference(select_det, select_rec)
|