Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -115,7 +115,41 @@ def launch_prediction(cropped_image, score_threshold, is_mobile, screen_width):
|
|
115 |
|
116 |
from modules.eval import develop_prediction, generate_data
|
117 |
from modules.utils import class_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
|
|
119 |
|
120 |
|
121 |
def display_bpmn_modeler(is_mobile, screen_width):
|
|
|
115 |
|
116 |
from modules.eval import develop_prediction, generate_data
|
117 |
from modules.utils import class_dict
|
118 |
+
from modules.eval import develop_prediction, generate_data
|
119 |
+
from modules.utils import class_dict
|
120 |
+
def modify_results(percentage_text_dist_thresh=0.5):
|
121 |
+
with st.expander("Method and Style modification (beta version)"):
|
122 |
+
label_list = list(class_dict.values())
|
123 |
+
bboxes = [[int(coord) for coord in box] for box in st.session_state.prediction['boxes']]
|
124 |
+
for i in range(len(bboxes)):
|
125 |
+
bboxes[i][2] = bboxes[i][2] - bboxes[i][0]
|
126 |
+
bboxes[i][3] = bboxes[i][3] - bboxes[i][1]
|
127 |
+
labels = [int(label) for label in st.session_state.prediction['labels']]
|
128 |
+
uploaded_image = prepare_image(st.session_state.crop_image, new_size=(1333, 1333), pad=False)
|
129 |
+
scale = 2000 / uploaded_image.size[0]
|
130 |
+
new_labels = detection(
|
131 |
+
image=uploaded_image, bboxes=bboxes, labels=labels,
|
132 |
+
label_list=label_list, line_width=3, width=2000, use_space=False
|
133 |
+
)
|
134 |
+
|
135 |
+
if new_labels is not None:
|
136 |
+
new_lab = np.array([label['label_id'] for label in new_labels])
|
137 |
+
|
138 |
+
# Convert back to original format
|
139 |
+
bboxes = np.array([label['bbox'] for label in new_labels])
|
140 |
+
for i in range(len(bboxes)):
|
141 |
+
bboxes[i][2] = bboxes[i][2] + bboxes[i][0]
|
142 |
+
bboxes[i][3] = bboxes[i][3] + bboxes[i][1]
|
143 |
+
|
144 |
+
scores = st.session_state.prediction['scores']
|
145 |
+
keypoints = st.session_state.prediction['keypoints']
|
146 |
+
#print('Old prediction:', st.session_state.prediction['keypoints'])
|
147 |
+
boxes, labels, scores, keypoints, flow_links, best_points, pool_dict = develop_prediction(bboxes, new_lab, scores, keypoints, class_dict, correction=False)
|
148 |
+
|
149 |
+
st.session_state.prediction = generate_data(st.session_state.prediction['image'], boxes, labels, scores, keypoints, flow_links, best_points, pool_dict, class_dict)
|
150 |
+
st.session_state.text_mapping = mapping_text(st.session_state.prediction, st.session_state.text_pred, print_sentences=False, percentage_thresh=percentage_text_dist_thresh)
|
151 |
|
152 |
+
#print('New prediction:', st.session_state.prediction['keypoints'])
|
153 |
|
154 |
|
155 |
def display_bpmn_modeler(is_mobile, screen_width):
|