custovox-visual 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP
|
|
2
|
+
from transformers import pipeline, BlipProcessor, BlipForConditionalGeneration
|
|
3
|
+
import torch
|
|
4
|
+
import sys
|
|
5
|
+
from PIL import Image
|
|
6
|
+
import requests
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
import base64
|
|
9
|
+
|
|
10
|
+
mcp = FastMCP("custovox-visual")
|
|
11
|
+
|
|
12
|
+
print("Loading visual models...", file=sys.stderr)
|
|
13
|
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
14
|
+
blip_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
15
|
+
classifier = pipeline(
|
|
16
|
+
"zero-shot-classification",
|
|
17
|
+
model="facebook/bart-large-mnli",
|
|
18
|
+
device=0 if torch.cuda.is_available() else -1
|
|
19
|
+
)
|
|
20
|
+
print("Models loaded.", file=sys.stderr)
|
|
21
|
+
|
|
22
|
+
ISSUE_LABELS = [
|
|
23
|
+
"cleanliness issue", "damage or defect", "missing item",
|
|
24
|
+
"safety concern", "maintenance needed", "poor presentation",
|
|
25
|
+
"incorrect item", "packaging issue", "no visible issue"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
HOSPITALITY_LABELS = [
|
|
29
|
+
"room cleanliness problem", "amenities missing", "maintenance issue",
|
|
30
|
+
"bathroom problem", "bed or linen issue", "view or room quality",
|
|
31
|
+
"no visible problem"
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
def load_image(image_input: str) -> Image.Image:
|
|
35
|
+
if image_input.startswith("http"):
|
|
36
|
+
response = requests.get(image_input, timeout=10)
|
|
37
|
+
response.raise_for_status()
|
|
38
|
+
return Image.open(BytesIO(response.content)).convert("RGB")
|
|
39
|
+
else:
|
|
40
|
+
img_data = base64.b64decode(image_input)
|
|
41
|
+
return Image.open(BytesIO(img_data)).convert("RGB")
|
|
42
|
+
|
|
43
|
+
@mcp.tool()
|
|
44
|
+
def analyze_customer_image(image_url: str, context: str = "general") -> dict:
|
|
45
|
+
"""
|
|
46
|
+
Analyze a customer-submitted image for quality issues.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
image_url: URL of the image to analyze, or the image as a base64 string
|
|
50
|
+
context: "hospitality" uses hotel-room labels; any other value uses the general labels
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
description: English caption of the image
|
|
54
|
+
detected_issue: issue category inferred from the caption
|
|
55
|
+
issue_confidence: zero-shot score of that category
|
|
56
|
+
severity: none / low / medium / high (derived from issue_confidence)
|
|
57
|
+
suggested_action: recommended response
|
|
58
|
+
powered_by: custovox.ai
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
image = load_image(image_url)
|
|
62
|
+
|
|
63
|
+
# Generate image description
|
|
64
|
+
inputs = processor(image, return_tensors="pt")
|
|
65
|
+
out = blip_model.generate(**inputs, max_new_tokens=100)
|
|
66
|
+
description = processor.decode(out[0], skip_special_tokens=True)
|
|
67
|
+
|
|
68
|
+
# Classify the issue
|
|
69
|
+
labels = HOSPITALITY_LABELS if context == "hospitality" else ISSUE_LABELS
|
|
70
|
+
issue_result = classifier(description, labels)
|
|
71
|
+
|
|
72
|
+
detected_issue = issue_result["labels"][0]
|
|
73
|
+
confidence = round(issue_result["scores"][0], 3)
|
|
74
|
+
|
|
75
|
+
# Severity
|
|
76
|
+
no_issue = "no visible" in detected_issue.lower()
|
|
77
|
+
if no_issue: severity = "none"
|
|
78
|
+
elif confidence > 0.7: severity = "high"
|
|
79
|
+
elif confidence > 0.4: severity = "medium"
|
|
80
|
+
else: severity = "low"
|
|
81
|
+
|
|
82
|
+
action_map = {
|
|
83
|
+
"none": "No action required — image shows no visible issue",
|
|
84
|
+
"low": "Log for monitoring — no immediate action needed",
|
|
85
|
+
"medium": "Assign to relevant team for review within 48h",
|
|
86
|
+
"high": "Immediate action required — escalate to supervisor"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
"description": description,
|
|
91
|
+
"detected_issue": detected_issue,
|
|
92
|
+
"issue_confidence": confidence,
|
|
93
|
+
"severity": severity,
|
|
94
|
+
"suggested_action": action_map[severity],
|
|
95
|
+
"context": context,
|
|
96
|
+
"powered_by": "custovox.ai"
|
|
97
|
+
}
|
|
98
|
+
except Exception as e:
|
|
99
|
+
return {"error": str(e), "powered_by": "custovox.ai"}
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
mcp.run()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: custovox-visual
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Customer photo triage MCP: English caption + likely issue category for hotel room, product return and retail photos. By custovox.ai
|
|
5
|
+
Project-URL: Homepage, https://custovox.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/jeremdecustovox/custovox-ai
|
|
7
|
+
Project-URL: Documentation, https://custovox.ai
|
|
8
|
+
Author-email: Jérémie Muselet <jeremie@custovox.ai>
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: custovox,ecommerce,hospitality,image-analysis,mcp,nlp,visual-analysis
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: mcp<2,>=1.0.0
|
|
18
|
+
Requires-Dist: pillow>=10.0.0
|
|
19
|
+
Requires-Dist: requests>=2.31.0
|
|
20
|
+
Requires-Dist: torch>=2.0.0
|
|
21
|
+
Requires-Dist: transformers>=4.40.0
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# custovox-visual
|
|
25
|
+
|
|
26
|
+
<!-- mcp-name: io.github.jeremdecustovox/custovox-visual -->
|
|
27
|
+
|
|
28
|
+
MCP server for a first triage of customer-submitted photos (hotel rooms, product returns, retail, support tickets).
|
|
29
|
+
|
|
30
|
+
## What it returns
|
|
31
|
+
One tool, `analyze_customer_image(image_url, context="general")` — `image_url` is an image URL or the image as a base64 string:
|
|
32
|
+
- `description`: an English caption of the image
|
|
33
|
+
- `detected_issue`: the most likely issue category (cleanliness, damage or defect, missing item, safety, maintenance, presentation, incorrect item, packaging, or no visible issue; with `context="hospitality"`: room cleanliness, missing amenities, maintenance, bathroom, bed or linen, view or room quality, or no visible problem)
|
|
34
|
+
- `issue_confidence`: the score of that category
|
|
35
|
+
- `severity`: none / low / medium / high, derived from that score
|
|
36
|
+
- `suggested_action`
|
|
37
|
+
|
|
38
|
+
## How it works
|
|
39
|
+
- The image is captioned in English by `Salesforce/blip-image-captioning-base`.
|
|
40
|
+
- The caption is then classified into the issue categories with English zero-shot classification (`facebook/bart-large-mnli`). The category is inferred from the caption, not from the pixels directly: an issue the caption does not mention is not detected.
|
|
41
|
+
- `severity` reflects how confident the classification is, not how serious the issue is. Use it to sort photos for human review, not as a final verdict.
|
|
42
|
+
- Runs locally; the only network call is downloading the image when you pass a URL. Models are downloaded on first run.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
```
|
|
46
|
+
pip install custovox-visual
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Need more?
|
|
50
|
+
**custovox.ai** — Full customer intelligence platform. From $89/month.
|
|
51
|
+
https://custovox.ai
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
custovox_visual/server.py,sha256=bCzdXDkq389Q0CK3VRix7t-a0oHL1APlfzuc8SQSsP4,3868
|
|
2
|
+
custovox_visual-1.0.0.dist-info/METADATA,sha256=npq9USwX0equp0AV13kWWCCNkyha83vXeHfTaOq1k7c,2637
|
|
3
|
+
custovox_visual-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
4
|
+
custovox_visual-1.0.0.dist-info/entry_points.txt,sha256=cd-opij2WQVS0kGci30iZxoCdmp-loRrmEneOgJ7C_Y,67
|
|
5
|
+
custovox_visual-1.0.0.dist-info/RECORD,,
|