-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_detection.py
More file actions
53 lines (43 loc) · 2.2 KB
/
object_detection.py
File metadata and controls
53 lines (43 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from vertexai.generative_models import (GenerationConfig, GenerativeModel, Part)
import vertexai
import config
# --- Configure Vertex AI ---
PROJECT_ID = config.PROJECT_ID
LOCATION = config.LOCATION
def analyze_media_with_gemini(media_uri, mime_type): # New function name
"""Analyzes media (image or video) with Gemini."""
try:
vertexai.init(project=PROJECT_ID, location=LOCATION)
model = GenerativeModel("gemini-1.5-pro-002") # Or your chosen model
response_schema = { #This can remain the same
"type": "array",
"items": {
"type": "object",
"properties": {
"item": {"type": "string"},
"brand": {"type": "string"},
"model": {"type": "string"},
"quantity": {"type": "integer"},
"description": {"type": "string"},
"timestamp": {"type": "string"}, # you might adjust this if you are dealing with images.
},
"required": ["item", "quantity", "description", "timestamp"], # And this
},
}
response = model.generate_content(
[
"""You are an insurance adjuster creating a home inventory. Analyze this media and return a JSON array of objects, each describing an item seen.
Include item, brand, model (if possible), quantity, and brief description of the item.
Only include items that are clearly visible and fully within the frame.
Exclude partially visible or ambiguous objects.
For each item, include relevant information such as timestamps (for videos) or location within the image (for images).""", # Slightly improved prompt
Part.from_uri(media_uri, mime_type=mime_type), # Use mime_type
],
generation_config=GenerationConfig(
response_mime_type="application/json", response_schema=response_schema
),
)
return response.text
except Exception as e:
return json.dumps({"error": f"Gemini API call failed: {e}"})