help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
real-estate-bot
/
src
RSK World
real-estate-bot
Real Estate Bot - Python + Flask + OpenAI + SQLite + Property Search + AI Chatbot + Viewing Scheduler
src
  • __pycache__
  • __init__.py476 B
  • ai_recommendation_engine.py20.6 KB
  • app.py7.8 KB
  • blockchain_integration.py1.5 KB
  • chatbot.py15.5 KB
  • database.py18.4 KB
  • image_enhancer.py7.9 KB
  • multilang_support.py8.8 KB
  • neighborhood_analyzer.py6.1 KB
  • price_prediction_engine.py25.1 KB
  • property_search.py15.6 KB
  • virtual_tour_manager.py21.8 KB
  • voice_assistant.py27.6 KB
CONTRIBUTING.mdapp.py
src/app.py
Raw Download
Find: Go to:
"""
Real Estate Chatbot Application
Author: RSK World (https://rskworld.in)
Founded by: Molla Samser
Designer & Tester: Rima Khatun
Contact: info@rskworld.com, +91 93305 39277
Year: 2026
Description: Real estate chatbot for property search, inquiries, and scheduling viewings
"""

import os
import sqlite3
from datetime import datetime
from flask import Flask, render_template, request, jsonify, session
try:
    from flask_cors import CORS
except ImportError:
    CORS = None
from dotenv import load_dotenv
try:
    from openai import OpenAI
    openai_available = True
except ImportError:
    OpenAI = None
    openai_available = False
from src.chatbot import RealEstateChatbot
from src.database import DatabaseManager
from src.property_search import PropertySearchEngine
from src.ai_recommendation_engine import AIRecommendationEngine
from src.virtual_tour_manager import VirtualTourManager
from src.price_prediction_engine import PricePredictionEngine
from src.voice_assistant import VoiceAssistant
from src.neighborhood_analyzer import NeighborhoodAnalyzer
from src.blockchain_integration import BlockchainPropertyManager
from src.image_enhancer import ImageEnhancer
from src.multilang_support import MultiLanguageSupport

# Load environment variables
load_dotenv()

app = Flask(__name__)
app.secret_key = os.getenv('SECRET_KEY', 'default_secret_key')
if CORS:
    CORS(app)

# Initialize OpenAI
if openai_available:
    openai_client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
else:
    openai_client = None

# Initialize components with error handling
db_manager = DatabaseManager()
property_search = PropertySearchEngine()

try:
    chatbot = RealEstateChatbot(openai_client, property_search, db_manager)
except Exception as e:
    print(f"Chatbot not available: {e}")
    chatbot = None

try:
    ai_recommender = AIRecommendationEngine(db_manager)
except Exception as e:
    print(f"AI Recommendation Engine not available: {e}")
    ai_recommender = None

try:
    virtual_tour_manager = VirtualTourManager(db_manager)
except Exception as e:
    print(f"Virtual Tour Manager not available: {e}")
    virtual_tour_manager = None

try:
    price_predictor = PricePredictionEngine(db_manager)
except Exception as e:
    print(f"Price Prediction Engine not available: {e}")
    price_predictor = None

try:
    voice_assistant = VoiceAssistant(chatbot, db_manager)
except Exception as e:
    print(f"Voice Assistant not available: {e}")
    voice_assistant = None

try:
    neighborhood_analyzer = NeighborhoodAnalyzer()
except Exception as e:
    print(f"Neighborhood Analyzer not available: {e}")
    neighborhood_analyzer = None

try:
    blockchain_manager = BlockchainPropertyManager()
except Exception as e:
    print(f"Blockchain Manager not available: {e}")
    blockchain_manager = None

try:
    image_enhancer = ImageEnhancer()
except Exception as e:
    print(f"Image Enhancer not available: {e}")
    image_enhancer = None

try:
    multilang_support = MultiLanguageSupport()
except Exception as e:
    print(f"Multi-Language Support not available: {e}")
    multilang_support = None

@app.route('/')
def index():
    """Render the main chat interface"""
    return render_template('index.html')

@app.route('/api/chat', methods=['POST'])
def chat():
    """Handle chat messages"""
    try:
        if chatbot is None:
            return jsonify({
                'success': False,
                'error': 'Chatbot is not available. Please check the configuration.'
            }), 503
        
        data = request.get_json()
        user_message = data.get('message', '')
        user_id = session.get('user_id', 'anonymous')
        
        # Get chatbot response
        response = chatbot.process_message(user_message, user_id)
        
        return jsonify({
            'success': True,
            'response': response,
            'timestamp': datetime.now().isoformat()
        })
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.route('/api/properties/search', methods=['POST'])
def search_properties():
    """Search for properties based on criteria"""
    try:
        data = request.get_json()
        criteria = data.get('criteria', {})
        
        properties = property_search.search(criteria)
        
        return jsonify({
            'success': True,
            'properties': properties,
            'count': len(properties)
        })
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.route('/api/properties/<int:property_id>')
def get_property(property_id):
    """Get detailed information about a specific property"""
    try:
        property_info = property_search.get_property_by_id(property_id)
        
        if property_info:
            return jsonify({
                'success': True,
                'property': property_info
            })
        else:
            return jsonify({
                'success': False,
                'error': 'Property not found'
            }), 404
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.route('/api/appointments/schedule', methods=['POST'])
def schedule_appointment():
    """Schedule a property viewing"""
    try:
        data = request.get_json()
        user_id = session.get('user_id', 'anonymous')
        
        appointment_id = db_manager.schedule_appointment(
            user_id=user_id,
            property_id=data.get('property_id'),
            date_time=data.get('date_time'),
            contact_info=data.get('contact_info')
        )
        
        return jsonify({
            'success': True,
            'appointment_id': appointment_id,
            'message': 'Appointment scheduled successfully'
        })
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.route('/api/appointments/<user_id>')
def get_appointments(user_id):
    """Get user's scheduled appointments"""
    try:
        appointments = db_manager.get_user_appointments(user_id)
        
        return jsonify({
            'success': True,
            'appointments': appointments
        })
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.route('/api/inquiries/submit', methods=['POST'])
def submit_inquiry():
    """Submit a property inquiry"""
    try:
        data = request.get_json()
        user_id = session.get('user_id', 'anonymous')
        
        inquiry_id = db_manager.create_inquiry(
            user_id=user_id,
            property_id=data.get('property_id'),
            message=data.get('message'),
            contact_info=data.get('contact_info')
        )
        
        return jsonify({
            'success': True,
            'inquiry_id': inquiry_id,
            'message': 'Inquiry submitted successfully'
        })
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

@app.errorhandler(404)
def not_found(error):
    return render_template('404.html'), 404

@app.errorhandler(500)
def internal_error(error):
    return render_template('500.html'), 500

if __name__ == '__main__':
    # Initialize database
    db_manager.initialize_database()
    
    # Run the application
    host = os.getenv('FLASK_HOST', '0.0.0.0')
    port = int(os.getenv('FLASK_PORT', os.environ.get('PORT', 5000)))
    debug = os.getenv('FLASK_DEBUG', 'False').lower() == 'true'
    app.run(host=host, port=port, debug=debug)
268 lines•7.8 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer