Update app.py
Browse files
app.py
CHANGED
|
@@ -31,6 +31,12 @@ class Vehicle(BaseModel):
|
|
| 31 |
Make: str = Field(..., examples=["Toyota", "Honda", "Ford", "Suzuki"], description="The Make of the vehicle.")
|
| 32 |
Model: str = Field(..., examples=["Corolla", "Civic", "F-150"], description="The Model of the vehicle.")
|
| 33 |
Color: str = Field(..., example=["Red", "Blue", "Black", "White"], description="Return the color of the vehicle.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Parser for vehicle details
|
| 36 |
parser = JsonOutputParser(pydantic_object=Vehicle)
|
|
@@ -64,11 +70,22 @@ def display_image_grid(image_paths, rows=2, cols=3, figsize=(10, 7)):
|
|
| 64 |
@chain
|
| 65 |
def prompt(inputs):
|
| 66 |
prompt = [
|
| 67 |
-
SystemMessage(content="""You are an AI assistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
HumanMessage(
|
| 69 |
-
content=[
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
)
|
| 73 |
]
|
| 74 |
return prompt
|
|
|
|
| 31 |
Make: str = Field(..., examples=["Toyota", "Honda", "Ford", "Suzuki"], description="The Make of the vehicle.")
|
| 32 |
Model: str = Field(..., examples=["Corolla", "Civic", "F-150"], description="The Model of the vehicle.")
|
| 33 |
Color: str = Field(..., example=["Red", "Blue", "Black", "White"], description="Return the color of the vehicle.")
|
| 34 |
+
Year: str = Field(None, description="The year of the vehicle.")
|
| 35 |
+
Condition: str = Field(None, description="The condition of the vehicle.")
|
| 36 |
+
Logo: str = Field(None, description="The visible logo of the vehicle, if applicable.")
|
| 37 |
+
Damage: str = Field(None, description="Any visible damage or wear and tear on the vehicle.")
|
| 38 |
+
Region: str = Field(None, description="Region or country based on the license plate or clues from the image.")
|
| 39 |
+
PlateType: str = Field(None, description="Type of license plate, e.g., government, personal.")
|
| 40 |
|
| 41 |
# Parser for vehicle details
|
| 42 |
parser = JsonOutputParser(pydantic_object=Vehicle)
|
|
|
|
| 70 |
@chain
|
| 71 |
def prompt(inputs):
|
| 72 |
prompt = [
|
| 73 |
+
SystemMessage(content="""You are an AI assistant tasked with extracting detailed information from a vehicle image. Please extract the following details:
|
| 74 |
+
- Vehicle type (e.g., Car, Truck, Bus)
|
| 75 |
+
- License plate number and type (if identifiable, such as personal, commercial, government)
|
| 76 |
+
- Vehicle make, model, and year (e.g., 2020 Toyota Corolla)
|
| 77 |
+
- Vehicle color and condition (e.g., Red, well-maintained, damaged)
|
| 78 |
+
- Any visible brand logos or distinguishing marks (e.g., Tesla logo)
|
| 79 |
+
- Details of any visible damage (e.g., scratches, dents)
|
| 80 |
+
- Vehicle’s region or country (based on the license plate or other clues)
|
| 81 |
+
If some details are unclear or not visible, return `None` for those fields. Do not guess or provide inaccurate information."""
|
| 82 |
+
),
|
| 83 |
HumanMessage(
|
| 84 |
+
content=[
|
| 85 |
+
{"type": "text", "text": "Analyze the vehicle in the image and extract as many details as possible, including type, license plate, make, model, year, condition, damage, etc."},
|
| 86 |
+
{"type": "text", "text": instructions}, # include any other format instructions here
|
| 87 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{inputs['image']}", "detail": "low"}}
|
| 88 |
+
]
|
| 89 |
)
|
| 90 |
]
|
| 91 |
return prompt
|