sksameermujahid commited on
Commit
196e727
·
verified ·
1 Parent(s): 566f82a

Update newapp.py

Browse files
Files changed (1) hide show
  1. newapp.py +65 -85
newapp.py CHANGED
@@ -162,48 +162,49 @@ def get_location():
162
  @app.route('/verify', methods=['POST'])
163
  def verify_property():
164
  try:
165
- if not request.form and not request.files:
166
- logger.warning("No form data or files provided")
167
- return jsonify({
168
- 'error': 'No data provided',
169
- 'status': 'error'
170
- }), 400
171
-
172
- data = {
173
- 'property_name': request.form.get('property_name', '').strip(),
174
- 'property_type': request.form.get('property_type', '').strip(),
175
- 'status': request.form.get('status', '').strip(),
176
- 'description': request.form.get('description', '').strip(),
177
- 'address': request.form.get('address', '').strip(),
178
- 'city': request.form.get('city', '').strip(),
179
- 'state': request.form.get('state', '').strip(),
180
- 'country': request.form.get('country', 'India').strip(),
181
- 'zip': request.form.get('zip', '').strip(),
182
- 'latitude': request.form.get('latitude', '').strip(),
183
- 'longitude': request.form.get('longitude', '').strip(),
184
- 'bedrooms': request.form.get('bedrooms', '').strip(),
185
- 'bathrooms': request.form.get('bathrooms', '').strip(),
186
- 'total_rooms': request.form.get('total_rooms', '').strip(),
187
- 'year_built': request.form.get('year_built', '').strip(),
188
- 'parking': request.form.get('parking', '').strip(),
189
- 'sq_ft': request.form.get('sq_ft', '').strip(),
190
- 'market_value': request.form.get('market_value', '').strip(),
191
- 'amenities': request.form.get('amenities', '').strip(),
192
- 'nearby_landmarks': request.form.get('nearby_landmarks', '').strip(),
193
- 'legal_details': request.form.get('legal_details', '').strip()
194
- }
195
 
196
- required_fields = ['property_name', 'property_type', 'address', 'city', 'state']
197
- missing_fields = [field for field in required_fields if not data[field]]
198
- if missing_fields:
199
- logger.warning(f"Missing required fields: {', '.join(missing_fields)}")
200
  return jsonify({
201
- 'error': f"Missing required fields: {', '.join(missing_fields)}",
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
- pdf_texts = []
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['property_name']}
241
- Property Type: {data['property_type']}
242
- Status: {data['status']}
243
- Description: {data['description']}
244
- Location: {data['address']}, {data['city']}, {data['state']}, {data['country']}, {data['zip']}
245
- Coordinates: Lat {data['latitude']}, Long {data['longitude']}
246
- Specifications: {data['bedrooms']} bedrooms, {data['bathrooms']} bathrooms, {data['total_rooms']} total rooms
247
- Year Built: {data['year_built']}
248
- Parking: {data['parking']}
249
- Size: {data['sq_ft']} sq. ft.
250
- Market Value: ₹{data['market_value']}
251
- Amenities: {data['amenities']}
252
- Nearby Landmarks: {data['nearby_landmarks']}
253
- Legal Details: {data['legal_details']}
254
  """
255
 
256
- try:
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['description_translated'])
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['legal_details'])
281
  specs_verification = verify_property_specs(data)
282
  market_analysis = analyze_market_value(data)
283
 
284
- document_analysis = {
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
- 'images': images
 
 
 
 
 
 
 
 
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))