A modern, elegant web application for AI-powered stock recommendations with a sophisticated frontend and Flask backend.
Create a requirements.txt file with the following:
flask>=2.0.0
flask-cors>=3.0.0
pandas>=1.5.0
numpy>=1.20.0
scikit-learn>=1.0.0
lightgbm>=3.0.0
joblib>=1.0.0
yfinance>=0.1.0# Install dependencies
pip install -r requirements.txt
# Or install individually:
pip install flask flask-cors pandas numpy scikit-learn lightgbm joblib yfinanceYour project directory should look like this:
ai-stock-advisor/
├── server.py # Flask backend server
├── index.html # Frontend web interface
├── requirements.txt # Python dependencies
├── feature_engineered_data.csv # Your processed data
├── short_term_model.joblib # 30-day model
├── medium_term_model.joblib # 90-day model
├── long_term_model.joblib # 365-day model
└── README.md # This file
-
Ensure your models and data are ready:
- Run your existing Jupyter notebook to generate the required files
- Make sure you have:
feature_engineered_data.csvand the three.joblibmodel files
-
Save the frontend:
- Save the HTML code as
index.htmlin your project directory
- Save the HTML code as
-
Save the backend:
- Save the Python server code as
server.py
- Save the Python server code as
-
Install dependencies:
pip install -r requirements.txt
-
Start the server:
python server.py
-
Open your browser:
- Navigate to
http://localhost:5000 - The modern web interface will load automatically
- Navigate to
Get stock recommendations based on user preferences.
Request Body:
{
"risk_level": "Medium",
"time_horizon": "medium",
"num_stocks": 10
}Response:
{
"success": true,
"recommendations": [
{
"symbol": "RELIANCE.NS",
"price": 2456.75,
"volatility": 0.0234,
"volume": 1234567,
"rsi": 65.4,
"macd": 12.3
}
],
"parameters": {
"risk_level": "Medium",
"time_horizon": "medium",
"num_stocks": 10
}
}Get historical price data for charting.
Response:
{
"symbol": "RELIANCE.NS",
"dates": ["2023-01-01", "2023-01-02", ...],
"close": [2400, 2405, ...],
"sma_20": [2390, 2392, ...],
"sma_50": [2385, 2387, ...],
"volume": [1000000, 1100000, ...]
}Check server status and loaded data.
- Modern Design: Glass-morphism effects, gradients, and smooth animations
- Responsive Layout: Works perfectly on desktop, tablet, and mobile
- Interactive Controls: Intuitive sliders and dropdowns for user preferences
- Real-time Charts: Interactive price charts using Chart.js
- Loading States: Professional loading indicators and transitions
- Error Handling: Graceful error messages and troubleshooting guides
- RESTful API: Clean, well-documented endpoints
- Model Integration: Seamlessly loads and uses your trained models
- Data Processing: Handles feature engineering and predictions
- Error Handling: Comprehensive error catching and logging
- CORS Support: Enables frontend-backend communication
- Performance: Much faster loading and response times
- Customization: Full control over UI/UX design
- Scalability: Can handle multiple concurrent users
- Professional Look: Modern, polished interface
- API-First: Easy to integrate with mobile apps or other services
-
"Model files not found"
- Ensure you've run your Jupyter notebook to generate the
.joblibfiles - Check that all three model files are in the same directory as
server.py
- Ensure you've run your Jupyter notebook to generate the
-
"Feature-engineered data not found"
- Run the feature engineering script from your notebook
- Verify
feature_engineered_data.csvexists and has data
-
"Connection refused" or API errors
- Make sure the Flask server is running:
python server.py - Check that no other service is using port 5000
- Try accessing
http://localhost:5000/api/statusdirectly
- Make sure the Flask server is running:
-
Charts not loading
- Ensure the backend is returning chart data
- Check browser console for JavaScript errors
- Verify the stock symbol exists in your dataset
- Debug Mode: The server runs in debug mode by default for development
- Logging: Check the console output for detailed request/response information
- Data Validation: The server includes comprehensive input validation
- Model Performance: Each prediction includes performance metrics
For production use:
- Set
debug=Falsein the Flask app - Use a production WSGI server like Gunicorn
- Add proper authentication if needed
- Set up HTTPS with SSL certificates
- Configure CORS for your production domain
- The current setup is for development/demo purposes
- Add input validation and rate limiting for production
- Consider authentication for sensitive financial data
- Use HTTPS in production environments
- Add More Features: Portfolio optimization, backtesting, alerts
- Mobile App: Use the API to create a mobile application
- Real-time Data: Integrate live market data feeds
- User Accounts: Add user registration and portfolio tracking
- Advanced Charts: Add more technical indicators and chart types