Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +78 -66
src/streamlit_app.py
CHANGED
|
@@ -114,54 +114,39 @@ if run_button:
|
|
| 114 |
elif is_multisensor and not sensor_select:
|
| 115 |
st.session_state.error = "Please select a sensor or 'All sensors' before generating CSV."
|
| 116 |
else:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
metrics.append({
|
| 151 |
-
'name': getattr(sample, 'name', sample.uuid),
|
| 152 |
-
'uuid': sample.uuid,
|
| 153 |
-
'labelset': labelset,
|
| 154 |
-
'sensor': sensor_name,
|
| 155 |
-
'num_frames': num_frames,
|
| 156 |
-
'total_annotations': total_annotations,
|
| 157 |
-
'matching_annotations': matching_annotations,
|
| 158 |
-
'labeled_by': labeled_by,
|
| 159 |
-
'reviewed_by': reviewed_by
|
| 160 |
-
})
|
| 161 |
-
continue
|
| 162 |
-
else:
|
| 163 |
-
frames_list = export_frames_and_annotations(label)
|
| 164 |
-
sensor_val = ''
|
| 165 |
num_frames = len(frames_list)
|
| 166 |
total_annotations = sum(len(f['annotations']) for f in frames_list)
|
| 167 |
matching_annotations = sum(
|
|
@@ -170,25 +155,52 @@ if run_button:
|
|
| 170 |
for ann in f['annotations']
|
| 171 |
if getattr(ann, 'category_id', None) in target_classes
|
| 172 |
)
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
except Exception as e:
|
| 185 |
continue
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
if st.session_state.error:
|
| 194 |
st.error(st.session_state.error)
|
|
|
|
| 114 |
elif is_multisensor and not sensor_select:
|
| 115 |
st.session_state.error = "Please select a sensor or 'All sensors' before generating CSV."
|
| 116 |
else:
|
| 117 |
+
# Show loader/status message while checking dataset type and generating CSV
|
| 118 |
+
status_ctx = None
|
| 119 |
+
try:
|
| 120 |
+
status_ctx = st.status("Checking dataset type...", expanded=True)
|
| 121 |
+
except AttributeError:
|
| 122 |
+
st.info("Checking dataset type...")
|
| 123 |
+
try:
|
| 124 |
+
target_classes = parse_classes(classes_input)
|
| 125 |
+
client = init_client(api_key)
|
| 126 |
+
metrics = []
|
| 127 |
+
# Update loader after dataset type check
|
| 128 |
+
if status_ctx is not None:
|
| 129 |
+
status_ctx.update(label="Dataset type checked. Processing samples...", state="running")
|
| 130 |
+
for sample in samples_objects:
|
| 131 |
+
try:
|
| 132 |
+
label = client.get_label(sample.uuid)
|
| 133 |
+
labelset = getattr(label, 'labelset', '') or ''
|
| 134 |
+
labeled_by = getattr(label, 'created_by', '') or ''
|
| 135 |
+
reviewed_by = getattr(label, 'reviewed_by', '') or ''
|
| 136 |
+
if is_multisensor and sensor_select and sensor_select != 'All sensors':
|
| 137 |
+
frames_list = export_sensor_frames_and_annotations(label, sensor_select)
|
| 138 |
+
sensor_val = sensor_select
|
| 139 |
+
num_frames = len(frames_list)
|
| 140 |
+
total_annotations = sum(len(f['annotations']) for f in frames_list)
|
| 141 |
+
matching_annotations = sum(
|
| 142 |
+
1
|
| 143 |
+
for f in frames_list
|
| 144 |
+
for ann in f['annotations']
|
| 145 |
+
if getattr(ann, 'category_id', None) in target_classes
|
| 146 |
+
)
|
| 147 |
+
elif is_multisensor and (not sensor_select or sensor_select == 'All sensors'):
|
| 148 |
+
all_sensor_frames = export_all_sensor_frames_and_annotations(label)
|
| 149 |
+
for sensor_name, frames_list in all_sensor_frames.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
num_frames = len(frames_list)
|
| 151 |
total_annotations = sum(len(f['annotations']) for f in frames_list)
|
| 152 |
matching_annotations = sum(
|
|
|
|
| 155 |
for ann in f['annotations']
|
| 156 |
if getattr(ann, 'category_id', None) in target_classes
|
| 157 |
)
|
| 158 |
+
metrics.append({
|
| 159 |
+
'name': getattr(sample, 'name', sample.uuid),
|
| 160 |
+
'uuid': sample.uuid,
|
| 161 |
+
'labelset': labelset,
|
| 162 |
+
'sensor': sensor_name,
|
| 163 |
+
'num_frames': num_frames,
|
| 164 |
+
'total_annotations': total_annotations,
|
| 165 |
+
'matching_annotations': matching_annotations,
|
| 166 |
+
'labeled_by': labeled_by,
|
| 167 |
+
'reviewed_by': reviewed_by
|
| 168 |
+
})
|
|
|
|
| 169 |
continue
|
| 170 |
+
else:
|
| 171 |
+
frames_list = export_frames_and_annotations(label)
|
| 172 |
+
sensor_val = ''
|
| 173 |
+
num_frames = len(frames_list)
|
| 174 |
+
total_annotations = sum(len(f['annotations']) for f in frames_list)
|
| 175 |
+
matching_annotations = sum(
|
| 176 |
+
1
|
| 177 |
+
for f in frames_list
|
| 178 |
+
for ann in f['annotations']
|
| 179 |
+
if getattr(ann, 'category_id', None) in target_classes
|
| 180 |
+
)
|
| 181 |
+
metrics.append({
|
| 182 |
+
'name': getattr(sample, 'name', sample.uuid),
|
| 183 |
+
'uuid': sample.uuid,
|
| 184 |
+
'labelset': labelset,
|
| 185 |
+
'sensor': sensor_val if is_multisensor else '',
|
| 186 |
+
'num_frames': num_frames,
|
| 187 |
+
'total_annotations': total_annotations,
|
| 188 |
+
'matching_annotations': matching_annotations,
|
| 189 |
+
'labeled_by': labeled_by,
|
| 190 |
+
'reviewed_by': reviewed_by
|
| 191 |
+
})
|
| 192 |
+
except Exception as e:
|
| 193 |
+
continue
|
| 194 |
+
if not metrics:
|
| 195 |
+
st.session_state.error = "No metrics could be generated for the dataset."
|
| 196 |
+
else:
|
| 197 |
+
st.session_state.csv_content = generate_csv(metrics, dataset_identifier)
|
| 198 |
+
if status_ctx is not None:
|
| 199 |
+
status_ctx.update(label="CSV generated!", state="complete")
|
| 200 |
+
except Exception as e:
|
| 201 |
+
st.session_state.error = f"An error occurred: {e}"
|
| 202 |
+
if status_ctx is not None:
|
| 203 |
+
status_ctx.update(label="Error occurred.", state="error")
|
| 204 |
|
| 205 |
if st.session_state.error:
|
| 206 |
st.error(st.session_state.error)
|