ProjectsPDF Parser
API Usage Example for Uploading Part Photos
This route allows uploading a part photo with optional metadata.
API Usage Example for Uploading Part Photos
Route: POST /embed
This route allows uploading a part photo with optional metadata.
Request Format
The route accepts multipart/form-data with the following fields:
file(required) - image file (JPEG, PNG, etc.)metadata(optional) - JSON string with part metadata
Example 1: Upload Photo Without Metadata
import requests
# Open image file
with open('part_photo.jpg', 'rb') as f:
files = {'file': ('part_photo.jpg', f, 'image/jpeg')}
response = requests.post(
'http://34.139.6.131:8002/embed',
files=files
)
result = response.json()
print(f"Embedding dimension: {len(result['embedding'])}")
# 768 for CLIP-ViT-L-14Example 2: Upload Photo with Metadata for New Part
import requests
import json
# Create part metadata
metadata = {
"part_number": "ABC-12345",
"category": "engine",
"manufacturer": "Toyota",
"model": "Camry 2020",
"description": "Engine oil filter",
"price": 29.99,
"stock": 10,
"supplier_id": "SUP-001"
}
# Open image file
with open('part_photo.jpg', 'rb') as f:
files = {'file': ('part_photo.jpg', f, 'image/jpeg')}
data = {'metadata': json.dumps(metadata)}
response = requests.post(
'http://34.139.6.131:8002/embed',
files=files,
data=data
)
result = response.json()
print(f"Embedding: {result['embedding'][:5]}...") # First 5 values
print(f"Metadata: {result['metadata']}")Example 3: Using curl
# Without metadata
curl -X POST "http://34.139.6.131:8002/embed" \
-F "file=@part_photo.jpg"
# With metadata
curl -X POST "http://34.139.6.131:8002/embed" \
-F "file=@part_photo.jpg" \
-F 'metadata={"part_number":"ABC-12345","category":"engine","description":"Engine oil filter"}'Response Format
{
"embedding": [0.123, -0.456, 0.789, ...], // 768 numbers for CLIP-ViT-L-14
"metadata": {
"part_number": "ABC-12345",
"category": "engine",
"description": "Engine oil filter"
}
}Notes
-
Metadata as JSON string: Currently the API accepts metadata as a JSON string (
str), not as an object. This is required formultipart/form-data. -
Saving embedding: The embedding needs to be saved to the database (e.g., Weaviate) together with metadata for future search.
-
Complete workflow for new part:
# 1. Upload photo and get embedding response = requests.post('/embed', files={'file': ...}, data={'metadata': ...}) result = response.json() # 2. Save to Weaviate together with metadata and embedding weaviate_client.data_object.create( data_object={ **result['metadata'], # All metadata fields 'photo_url': 'https://...', # URL to photo }, class_name='Part', vector=result['embedding'] # CLIP embedding as vector )
Possible Improvement
The API could be improved to accept metadata as an object (dict) instead of a JSON string, but this would require changing the endpoint to application/json + base64 for the image, or keep it as is for convenience with multipart/form-data.