Spaces:
Running
Running
manual mode for multi-upload (fix)
Browse files
frontend/src/pages/UploadPage/UploadPage.tsx
CHANGED
|
@@ -481,10 +481,15 @@ export default function UploadPage() {
|
|
| 481 |
}
|
| 482 |
});
|
| 483 |
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
|
| 489 |
const mapRes = await fetch('/api/images/multi', { method: 'POST', body: fd });
|
| 490 |
const mapJson = await readJsonSafely(mapRes);
|
|
|
|
| 481 |
}
|
| 482 |
});
|
| 483 |
|
| 484 |
+
// Use manual mode if selected, otherwise use the selected model from localStorage
|
| 485 |
+
if (isManualMode) {
|
| 486 |
+
fd.append('model_name', 'manual');
|
| 487 |
+
} else {
|
| 488 |
+
const modelName = localStorage.getItem(SELECTED_MODEL_KEY);
|
| 489 |
+
if (modelName) {
|
| 490 |
+
fd.append('model_name', modelName);
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
|
| 494 |
const mapRes = await fetch('/api/images/multi', { method: 'POST', body: fd });
|
| 495 |
const mapJson = await readJsonSafely(mapRes);
|
py_backend/app/routers/upload.py
CHANGED
|
@@ -740,19 +740,28 @@ async def upload_multiple_images(
|
|
| 740 |
"fallback_reason": result.get("fallback_reason")
|
| 741 |
})
|
| 742 |
|
| 743 |
-
# Update individual image metadata if VLM provided it
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 756 |
|
| 757 |
# Ensure we never use 'random' as the model name in the database
|
| 758 |
final_model_name = actual_model if actual_model != "random" else "STUB_MODEL"
|
|
@@ -778,6 +787,8 @@ async def upload_multiple_images(
|
|
| 778 |
|
| 779 |
except Exception as e:
|
| 780 |
logger.debug(f"VLM error: {e}")
|
|
|
|
|
|
|
| 781 |
# Create fallback caption
|
| 782 |
fallback_text = f"Analysis of {len(image_bytes_list)} images"
|
| 783 |
caption = crud.create_caption(
|
|
|
|
| 740 |
"fallback_reason": result.get("fallback_reason")
|
| 741 |
})
|
| 742 |
|
| 743 |
+
# Update individual image metadata if VLM provided it (skip for manual mode)
|
| 744 |
+
if actual_model and actual_model.lower() != "manual":
|
| 745 |
+
metadata_images = metadata.get("metadata_images", {})
|
| 746 |
+
if metadata_images and isinstance(metadata_images, dict):
|
| 747 |
+
for i, img in enumerate(uploaded_images):
|
| 748 |
+
image_key = f"image{i+1}"
|
| 749 |
+
if image_key in metadata_images:
|
| 750 |
+
img_metadata = metadata_images[image_key]
|
| 751 |
+
if isinstance(img_metadata, dict):
|
| 752 |
+
# Update image with individual metadata only if values are not empty
|
| 753 |
+
vlm_source = img_metadata.get("source", "")
|
| 754 |
+
if vlm_source and vlm_source.strip():
|
| 755 |
+
img.source = vlm_source
|
| 756 |
+
vlm_event_type = img_metadata.get("type", "")
|
| 757 |
+
if vlm_event_type and vlm_event_type.strip():
|
| 758 |
+
img.event_type = vlm_event_type
|
| 759 |
+
vlm_epsg = img_metadata.get("epsg", "")
|
| 760 |
+
if vlm_epsg and vlm_epsg.strip():
|
| 761 |
+
img.epsg = vlm_epsg
|
| 762 |
+
vlm_countries = img_metadata.get("countries", [])
|
| 763 |
+
if vlm_countries:
|
| 764 |
+
img.countries = vlm_countries
|
| 765 |
|
| 766 |
# Ensure we never use 'random' as the model name in the database
|
| 767 |
final_model_name = actual_model if actual_model != "random" else "STUB_MODEL"
|
|
|
|
| 787 |
|
| 788 |
except Exception as e:
|
| 789 |
logger.debug(f"VLM error: {e}")
|
| 790 |
+
# Rollback any pending changes before creating fallback caption
|
| 791 |
+
db.rollback()
|
| 792 |
# Create fallback caption
|
| 793 |
fallback_text = f"Analysis of {len(image_bytes_list)} images"
|
| 794 |
caption = crud.create_caption(
|