Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,8 @@ def _build_vehicle_recognition_markdown(vision_results: dict[str, Any]) -> str:
|
|
| 43 |
method_note = "\nThe classifier can only predict one of the trained vehicle brands."
|
| 44 |
elif method == "fallback":
|
| 45 |
method_note = "\nNo trained model found. Please train the model first."
|
|
|
|
|
|
|
| 46 |
|
| 47 |
return f"""
|
| 48 |
### Vehicle recognition
|
|
@@ -142,19 +144,32 @@ def _run_advisor(
|
|
| 142 |
budget_chf,
|
| 143 |
max_monthly_rate_chf,
|
| 144 |
):
|
| 145 |
-
|
|
|
|
| 146 |
return (
|
| 147 |
-
"Please upload a car image.",
|
| 148 |
"No price estimate available yet.",
|
| 149 |
"No budget assessment available yet.",
|
| 150 |
"No financing orientation available yet.",
|
| 151 |
-
"Please
|
| 152 |
"No disclaimer available yet.",
|
| 153 |
{},
|
| 154 |
)
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
age = _normalize_age(car_age_years, "Age")
|
| 159 |
make_model_input = make_model.strip() if make_model and make_model.strip() else predicted_class
|
| 160 |
|
|
|
|
| 43 |
method_note = "\nThe classifier can only predict one of the trained vehicle brands."
|
| 44 |
elif method == "fallback":
|
| 45 |
method_note = "\nNo trained model found. Please train the model first."
|
| 46 |
+
elif method == "manual_input":
|
| 47 |
+
method_note = "\nCar brand/model entered manually without image analysis."
|
| 48 |
|
| 49 |
return f"""
|
| 50 |
### Vehicle recognition
|
|
|
|
| 144 |
budget_chf,
|
| 145 |
max_monthly_rate_chf,
|
| 146 |
):
|
| 147 |
+
# Allow either image OR manual make_model input, but require at least one
|
| 148 |
+
if image is None and not (make_model and make_model.strip()):
|
| 149 |
return (
|
| 150 |
+
"Please upload a car image OR enter a known make/model.",
|
| 151 |
"No price estimate available yet.",
|
| 152 |
"No budget assessment available yet.",
|
| 153 |
"No financing orientation available yet.",
|
| 154 |
+
"Please provide car details to start the analysis.",
|
| 155 |
"No disclaimer available yet.",
|
| 156 |
{},
|
| 157 |
)
|
| 158 |
|
| 159 |
+
# If image is provided, use vision analyzer; otherwise use manual input
|
| 160 |
+
if image is not None:
|
| 161 |
+
vision_results = analyze_car_image(image)
|
| 162 |
+
predicted_class = vision_results.get("predicted_class", "Unknown")
|
| 163 |
+
else:
|
| 164 |
+
# No image, but make_model was entered manually
|
| 165 |
+
predicted_class = "Unknown"
|
| 166 |
+
vision_results = {
|
| 167 |
+
"predicted_class": "Unknown",
|
| 168 |
+
"confidence": 0.0,
|
| 169 |
+
"method": "manual_input",
|
| 170 |
+
"notes": ["Car brand/model entered manually without image."],
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
age = _normalize_age(car_age_years, "Age")
|
| 174 |
make_model_input = make_model.strip() if make_model and make_model.strip() else predicted_class
|
| 175 |
|