Update newapp.py
Browse files
newapp.py
CHANGED
@@ -162,48 +162,49 @@ def get_location():
|
|
162 |
@app.route('/verify', methods=['POST'])
|
163 |
def verify_property():
|
164 |
try:
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
'nearby_landmarks': request.form.get('nearby_landmarks', '').strip(),
|
193 |
-
'legal_details': request.form.get('legal_details', '').strip()
|
194 |
-
}
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
logger.warning(f"Missing required fields: {', '.join(missing_fields)}")
|
200 |
return jsonify({
|
201 |
-
'error':
|
202 |
'status': 'error'
|
203 |
}), 400
|
204 |
|
|
|
205 |
images = []
|
206 |
image_analysis = []
|
|
|
|
|
|
|
|
|
207 |
if 'images' in request.files:
|
208 |
image_files = request.files.getlist('images')
|
209 |
for img_file in image_files:
|
@@ -219,8 +220,7 @@ def verify_property():
|
|
219 |
logger.error(f"Error processing image {img_file.filename}: {str(e)}")
|
220 |
image_analysis.append({'error': str(e), 'is_property_related': False})
|
221 |
|
222 |
-
|
223 |
-
pdf_analysis = []
|
224 |
if 'documents' in request.files:
|
225 |
pdf_files = request.files.getlist('documents')
|
226 |
for pdf_file in pdf_files:
|
@@ -236,66 +236,40 @@ def verify_property():
|
|
236 |
logger.error(f"Error processing PDF {pdf_file.filename}: {str(e)}")
|
237 |
pdf_analysis.append({'error': str(e)})
|
238 |
|
|
|
239 |
consolidated_text = f"""
|
240 |
-
Property Name: {data
|
241 |
-
Property Type: {data
|
242 |
-
Status: {data
|
243 |
-
Description: {data
|
244 |
-
Location: {data
|
245 |
-
Coordinates: Lat {data
|
246 |
-
Specifications: {data
|
247 |
-
Year Built: {data
|
248 |
-
Parking: {data
|
249 |
-
Size: {data
|
250 |
-
Market Value: ₹{data
|
251 |
-
Amenities: {data
|
252 |
-
Nearby Landmarks: {data
|
253 |
-
Legal Details: {data
|
254 |
"""
|
255 |
|
256 |
-
|
257 |
-
description = data['description']
|
258 |
-
if description and len(description) > 10:
|
259 |
-
text_language = detect(description)
|
260 |
-
if text_language != 'en':
|
261 |
-
translated_description = GoogleTranslator(source=text_language, target='en').translate(description)
|
262 |
-
data['description_translated'] = translated_description
|
263 |
-
else:
|
264 |
-
data['description_translated'] = description
|
265 |
-
else:
|
266 |
-
data['description_translated'] = description
|
267 |
-
except Exception as e:
|
268 |
-
logger.error(f"Error in language detection/translation: {str(e)}")
|
269 |
-
data['description_translated'] = data['description']
|
270 |
-
|
271 |
summary = generate_property_summary(data)
|
272 |
fraud_classification = classify_fraud(consolidated_text, data)
|
273 |
trust_score, trust_reasoning = generate_trust_score(consolidated_text, image_analysis, pdf_analysis)
|
274 |
suggestions = generate_suggestions(consolidated_text, data)
|
275 |
-
quality_assessment = assess_text_quality(data
|
276 |
address_verification = verify_address(data)
|
277 |
cross_validation = perform_cross_validation(data)
|
278 |
location_analysis = analyze_location(data)
|
279 |
price_analysis = analyze_price(data)
|
280 |
-
legal_analysis = analyze_legal_details(data
|
281 |
specs_verification = verify_property_specs(data)
|
282 |
market_analysis = analyze_market_value(data)
|
283 |
|
284 |
-
|
285 |
-
'pdf_count': len(pdf_texts),
|
286 |
-
'pdf_texts': pdf_texts,
|
287 |
-
'pdf_analysis': pdf_analysis
|
288 |
-
}
|
289 |
-
image_results = {
|
290 |
-
'image_count': len(images),
|
291 |
-
'image_analysis': image_analysis
|
292 |
-
}
|
293 |
-
|
294 |
-
report_id = str(uuid.uuid4())
|
295 |
-
|
296 |
results = {
|
297 |
-
'report_id': report_id,
|
298 |
-
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
299 |
'summary': summary,
|
300 |
'fraud_classification': fraud_classification,
|
301 |
'trust_score': {
|
@@ -309,11 +283,17 @@ def verify_property():
|
|
309 |
'location_analysis': location_analysis,
|
310 |
'price_analysis': price_analysis,
|
311 |
'legal_analysis': legal_analysis,
|
312 |
-
'document_analysis': document_analysis,
|
313 |
-
'image_analysis': image_results,
|
314 |
'specs_verification': specs_verification,
|
315 |
'market_analysis': market_analysis,
|
316 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
}
|
318 |
|
319 |
return jsonify(make_json_serializable(results))
|
|
|
162 |
@app.route('/verify', methods=['POST'])
|
163 |
def verify_property():
|
164 |
try:
|
165 |
+
# Handle both form data and JSON data
|
166 |
+
if request.is_json:
|
167 |
+
data = request.get_json()
|
168 |
+
else:
|
169 |
+
data = {
|
170 |
+
'property_name': request.form.get('property_name', '').strip(),
|
171 |
+
'property_type': request.form.get('property_type', '').strip(),
|
172 |
+
'status': request.form.get('status', '').strip(),
|
173 |
+
'description': request.form.get('description', '').strip(),
|
174 |
+
'address': request.form.get('address', '').strip(),
|
175 |
+
'city': request.form.get('city', '').strip(),
|
176 |
+
'state': request.form.get('state', '').strip(),
|
177 |
+
'country': request.form.get('country', 'India').strip(),
|
178 |
+
'zip': request.form.get('zip', '').strip(),
|
179 |
+
'latitude': request.form.get('latitude', '').strip(),
|
180 |
+
'longitude': request.form.get('longitude', '').strip(),
|
181 |
+
'bedrooms': request.form.get('bedrooms', '').strip(),
|
182 |
+
'bathrooms': request.form.get('bathrooms', '').strip(),
|
183 |
+
'total_rooms': request.form.get('total_rooms', '').strip(),
|
184 |
+
'year_built': request.form.get('year_built', '').strip(),
|
185 |
+
'parking': request.form.get('parking', '').strip(),
|
186 |
+
'sq_ft': request.form.get('sq_ft', '').strip(),
|
187 |
+
'market_value': request.form.get('market_value', '').strip(),
|
188 |
+
'amenities': request.form.get('amenities', '').strip(),
|
189 |
+
'nearby_landmarks': request.form.get('nearby_landmarks', '').strip(),
|
190 |
+
'legal_details': request.form.get('legal_details', '').strip()
|
191 |
+
}
|
|
|
|
|
|
|
192 |
|
193 |
+
# Check if we have at least some basic property information
|
194 |
+
if not any([data.get('property_name'), data.get('property_type'), data.get('address')]):
|
195 |
+
logger.warning("No basic property information provided")
|
|
|
196 |
return jsonify({
|
197 |
+
'error': 'Please provide at least property name, type, and address',
|
198 |
'status': 'error'
|
199 |
}), 400
|
200 |
|
201 |
+
# Initialize empty lists for images and documents
|
202 |
images = []
|
203 |
image_analysis = []
|
204 |
+
pdf_texts = []
|
205 |
+
pdf_analysis = []
|
206 |
+
|
207 |
+
# Process images if provided
|
208 |
if 'images' in request.files:
|
209 |
image_files = request.files.getlist('images')
|
210 |
for img_file in image_files:
|
|
|
220 |
logger.error(f"Error processing image {img_file.filename}: {str(e)}")
|
221 |
image_analysis.append({'error': str(e), 'is_property_related': False})
|
222 |
|
223 |
+
# Process documents if provided
|
|
|
224 |
if 'documents' in request.files:
|
225 |
pdf_files = request.files.getlist('documents')
|
226 |
for pdf_file in pdf_files:
|
|
|
236 |
logger.error(f"Error processing PDF {pdf_file.filename}: {str(e)}")
|
237 |
pdf_analysis.append({'error': str(e)})
|
238 |
|
239 |
+
# Create consolidated text for analysis
|
240 |
consolidated_text = f"""
|
241 |
+
Property Name: {data.get('property_name', '')}
|
242 |
+
Property Type: {data.get('property_type', '')}
|
243 |
+
Status: {data.get('status', '')}
|
244 |
+
Description: {data.get('description', '')}
|
245 |
+
Location: {data.get('address', '')}, {data.get('city', '')}, {data.get('state', '')}, {data.get('country', '')}, {data.get('zip', '')}
|
246 |
+
Coordinates: Lat {data.get('latitude', '')}, Long {data.get('longitude', '')}
|
247 |
+
Specifications: {data.get('bedrooms', '')} bedrooms, {data.get('bathrooms', '')} bathrooms, {data.get('total_rooms', '')} total rooms
|
248 |
+
Year Built: {data.get('year_built', '')}
|
249 |
+
Parking: {data.get('parking', '')}
|
250 |
+
Size: {data.get('sq_ft', '')} sq. ft.
|
251 |
+
Market Value: ₹{data.get('market_value', '')}
|
252 |
+
Amenities: {data.get('amenities', '')}
|
253 |
+
Nearby Landmarks: {data.get('nearby_landmarks', '')}
|
254 |
+
Legal Details: {data.get('legal_details', '')}
|
255 |
"""
|
256 |
|
257 |
+
# Perform all analyses regardless of images/documents
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
summary = generate_property_summary(data)
|
259 |
fraud_classification = classify_fraud(consolidated_text, data)
|
260 |
trust_score, trust_reasoning = generate_trust_score(consolidated_text, image_analysis, pdf_analysis)
|
261 |
suggestions = generate_suggestions(consolidated_text, data)
|
262 |
+
quality_assessment = assess_text_quality(data.get('description', ''))
|
263 |
address_verification = verify_address(data)
|
264 |
cross_validation = perform_cross_validation(data)
|
265 |
location_analysis = analyze_location(data)
|
266 |
price_analysis = analyze_price(data)
|
267 |
+
legal_analysis = analyze_legal_details(data.get('legal_details', ''))
|
268 |
specs_verification = verify_property_specs(data)
|
269 |
market_analysis = analyze_market_value(data)
|
270 |
|
271 |
+
# Prepare results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
results = {
|
|
|
|
|
273 |
'summary': summary,
|
274 |
'fraud_classification': fraud_classification,
|
275 |
'trust_score': {
|
|
|
283 |
'location_analysis': location_analysis,
|
284 |
'price_analysis': price_analysis,
|
285 |
'legal_analysis': legal_analysis,
|
|
|
|
|
286 |
'specs_verification': specs_verification,
|
287 |
'market_analysis': market_analysis,
|
288 |
+
'document_analysis': {
|
289 |
+
'pdf_count': len(pdf_texts),
|
290 |
+
'pdf_texts': pdf_texts,
|
291 |
+
'pdf_analysis': pdf_analysis
|
292 |
+
},
|
293 |
+
'image_analysis': {
|
294 |
+
'image_count': len(images),
|
295 |
+
'image_analysis': image_analysis
|
296 |
+
}
|
297 |
}
|
298 |
|
299 |
return jsonify(make_json_serializable(results))
|