Spaces:
Sleeping
Financial Advisor
Overview
The Financial Advisor is a web application that provides personalized financial advice and recommendations to users. It uses machine learning models and rule-based logic to suggest optimal investment allocations based on user inputs. The application is built using FastAPI, a modern, high-performance web framework for building APIs with Python.
Features
- User Authentication: Secure user registration and login system.
- Admin Dashboard: A dedicated dashboard for administrators to manage users and view system data.
- Chatbot Interface: An interactive chatbot that guides users through the process of providing financial information and receiving recommendations.
- Personalized Recommendations: Investment recommendations tailored to individual user profiles, risk tolerance, and financial goals.
- Multiple Models: Support for different recommendation models, including:
- Base Model: A basic model that considers salary, expenses, savings, lifecycle stage, risk appetite, and investment horizon.
- Enhanced Model: An advanced model that incorporates profession and city to provide more refined recommendations.
- Rule-Based Model: A model that uses predefined rules to generate recommendations based on user inputs.
- Stock Data: Real-time stock data fetching and display.
Modules
Admin Module
The Admin module provides functionalities for administrators to manage the application and its users.
- admin.py: Contains the API endpoints and logic for the admin dashboard and user management.
admin_dashboard_shell: Renders the admin dashboard HTML page.get_admin_dashboard_data: Fetches data for the admin dashboard, including user lists and search functionality.admin_view_user_details_shell: Renders the user details HTML page.get_admin_user_details_data: Fetches detailed information for a specific user.
User Module
The User module provides functionalities for users to interact with the application and receive financial advice.
- user.py: Contains the API endpoints and logic for user-related features, such as the chatbot and recommendations.
user_homepage: Renders the user homepage HTML page.chatbot_page: Renders the chatbot HTML page, allowing users to interact with the financial advisor.recommendations_page: Renders the recommendations HTML page, displaying market trends and stock recommendations.search_stocks: API endpoint for searching tickers.get_stock_price: API endpoint for fetching stock prices.
Authentication Module
The Authentication module handles user registration, login, and authentication.
- auth.py: Contains the API endpoints and logic for user authentication.
get_current_user: Retrieves the currently logged-in user.get_current_active_user: Retrieves the currently active user.get_current_admin_user: Retrieves the currently active admin user.signup_user: Registers a new user.login_for_access_token: Logs in a user and generates an access token.
Core Module
The Core module provides core functionalities and utilities for the application.
- core/security.py: Contains security-related functions, such as password hashing.
Database Module
The Database module handles database connections and operations.
- database.py: Contains functions for connecting to the database and creating tables.
get_db: Provides a database session.create_db_and_tables: Creates the database and tables if they don't exist.
Models Module
The Models module defines the database models.
- models.py: Contains the database models for users and user data inputs.
User: Represents a user in the system.UserDataInput: Represents user input data for the chatbot.
Schemas Module
The Schemas module defines the data schemas for API requests and responses.
- schemas.py: Contains the data schemas for users, user data inputs, and chatbot interactions.
Services Module
The Services module provides business logic and external integrations.
- services/chatbot_service.py: Contains the logic for processing chatbot interactions and generating recommendations.
process_chatbot_interaction: Processes user input and generates investment recommendations based on the selected model.predict_base_model: Predicts investment allocations using the base model.predict_enhanced_model: Predicts investment allocations using the enhanced model.predict_rule_based_model: Predicts investment allocations using the rule-based model.
- services/data_service.py: Contains functions for data handling, such as initializing the CSV file and appending data to it.
ML Models Module
The ML Models module contains the machine learning models used for generating recommendations.
- ml_models/basic_portfolio_model.pkl: The base machine learning model.
- ml_models/enhanced_portfolio_model.pkl: The enhanced machine learning model.