Spaces:
Sleeping
Sleeping
feat: allocate ZeroGPU for MiniCPM-V extraction
Browse filesBuilt with OpenAI Codex. Adds the required spaces.GPU wrapper for real local OpenBMB photo extraction.
- README.md +1 -0
- src/packetcourt/vlm.py +11 -1
README.md
CHANGED
|
@@ -28,6 +28,7 @@ verdicts instead of an unexplained health score.
|
|
| 28 |
|
| 29 |
- Reads front and back label photos with local OCR.
|
| 30 |
- Uses OpenBMB `MiniCPM-V-4.6` for local vision extraction when `PACKETCOURT_VLM=1`, with Tesseract fallback.
|
|
|
|
| 31 |
- Serves a fully custom responsive product interface with a mounted Gradio engine.
|
| 32 |
- Detects six common front claims.
|
| 33 |
- Links claims to ingredients, nutrition, FSSAI license, and expiry evidence.
|
|
|
|
| 28 |
|
| 29 |
- Reads front and back label photos with local OCR.
|
| 30 |
- Uses OpenBMB `MiniCPM-V-4.6` for local vision extraction when `PACKETCOURT_VLM=1`, with Tesseract fallback.
|
| 31 |
+
- Requests ZeroGPU only during MiniCPM-V photo extraction; text and prepared-case audits remain CPU-only.
|
| 32 |
- Serves a fully custom responsive product interface with a mounted Gradio engine.
|
| 33 |
- Detects six common front claims.
|
| 34 |
- Links claims to ingredients, nutrition, FSSAI license, and expiry evidence.
|
src/packetcourt/vlm.py
CHANGED
|
@@ -6,6 +6,16 @@ from pathlib import Path
|
|
| 6 |
|
| 7 |
MODEL_ID = os.getenv("PACKETCOURT_MODEL_ID", "openbmb/MiniCPM-V-4.6")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
PROMPTS = {
|
| 10 |
"front": (
|
| 11 |
"Transcribe the visible marketing claims on this food packet front. "
|
|
@@ -49,6 +59,7 @@ def model_status() -> dict[str, str | bool]:
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
|
|
|
| 52 |
def extract_with_vlm(image_path: str, side: str) -> str:
|
| 53 |
processor, model = _load_model()
|
| 54 |
messages = [
|
|
@@ -77,4 +88,3 @@ def extract_with_vlm(image_path: str, side: str) -> str:
|
|
| 77 |
)
|
| 78 |
trimmed = [output[len(source) :] for source, output in zip(inputs.input_ids, generated)]
|
| 79 |
return processor.batch_decode(trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0].strip()
|
| 80 |
-
|
|
|
|
| 6 |
|
| 7 |
MODEL_ID = os.getenv("PACKETCOURT_MODEL_ID", "openbmb/MiniCPM-V-4.6")
|
| 8 |
|
| 9 |
+
try:
|
| 10 |
+
import spaces
|
| 11 |
+
except ImportError:
|
| 12 |
+
class _SpacesFallback:
|
| 13 |
+
@staticmethod
|
| 14 |
+
def GPU(*_args, **_kwargs):
|
| 15 |
+
return lambda function: function
|
| 16 |
+
|
| 17 |
+
spaces = _SpacesFallback()
|
| 18 |
+
|
| 19 |
PROMPTS = {
|
| 20 |
"front": (
|
| 21 |
"Transcribe the visible marketing claims on this food packet front. "
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
|
| 62 |
+
@spaces.GPU(duration=180)
|
| 63 |
def extract_with_vlm(image_path: str, side: str) -> str:
|
| 64 |
processor, model = _load_model()
|
| 65 |
messages = [
|
|
|
|
| 88 |
)
|
| 89 |
trimmed = [output[len(source) :] for source, output in zip(inputs.input_ids, generated)]
|
| 90 |
return processor.batch_decode(trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0].strip()
|
|
|