Skip to content

kukadiyahiren/advance-python-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Advanced Python AI Web Suite

Advanced Python AI Web Suite

Full-stack AI web application combining Flask, FastAPI, DeepFace, OCR, and real-time NSE stock analytics.

Features β€’ Architecture β€’ Demo β€’ Installation

Stars Forks Views Downloads Python Flask FastAPI DeepFace OCR NSE License

Full-stack AI web application combining Flask, FastAPI, DeepFace, OCR, and NSE stock analytics.

Advanced Python Learning Project

A comprehensive Flask web application with FastAPI integration, featuring user management, image gallery, stock market dashboard, and AI-powered image processing.

πŸš€ Features

  • User Authentication - Secure login system with session management
  • User Management - Full CRUD operations via FastAPI REST API
  • Image Gallery - Upload and manage images with OCR text extraction
  • Stock Market Dashboard - Real-time Indian stock market data (NSE)
  • AI Hair Style Processing - Gender detection and hair style variants using DeepFace
  • FastAPI Integration - Modern REST API for user operations
  • Responsive UI - Modern glassmorphism design with smooth animations

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • MySQL Server
  • Tesseract OCR
  • Git

πŸ› οΈ Installation

1. Clone the Repository

git clone https://github.com/herrytest/advance-python-learning.git
cd advance-python-learning

2. Create Virtual Environment

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install flask mysql-connector-python pandas yfinance nsepython deepface easyocr opencv-python pytesseract psutil scikit-learn fastapi uvicorn pydantic

4. Install System Dependencies

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install tesseract-ocr mysql-server

macOS:

brew install tesseract mysql

5. Configure MySQL Database

# Login to MySQL
mysql -u root -p

# Create database and user
CREATE DATABASE laravel;
CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON laravel.* TO 'laravel'@'localhost';
FLUSH PRIVILEGES;
EXIT;

6. Update Database Configuration

Edit db.py if you need to change database credentials:

DB_CONFIG = {
    'user': 'laravel',
    'password': 'password',
    'host': '127.0.0.1',
    'database': 'laravel',
    'raise_on_warnings': False
}

7. Initialize Database

Before starting the application, run the migration script to create all necessary tables and seed initial data:

python3 apply_migration.py

8. Create Uploads Directory

mkdir -p uploads

πŸš€ Running the Application

Start Flask Application (Main App)

python app.py

The Flask app will run on: http://localhost:5000

Start FastAPI Service (User Management API)

Open a new terminal and run:

source venv/bin/activate  # Activate virtual environment
uvicorn fastapi_users:app --reload --port 8000

Or use the startup script:

./start_fastapi.sh

The FastAPI service will run on: http://localhost:8000

API Documentation: http://localhost:8000/docs

πŸ” Default Login Credentials

  • Username: admin
  • Password: 123456

πŸ“š API Endpoints

User Management (FastAPI)

  • POST /api/users - Create a new user
  • GET /api/users - Get all users
  • GET /api/users/{id} - Get user by ID
  • PUT /api/users/{id} - Update user
  • DELETE /api/users/{id} - Delete user

Test Endpoints

  • GET /api/test/hello - Simple hello world
  • GET /api/test/echo/{text} - Echo text with transformations
  • POST /api/test/calculate - Calculator API
  • GET /api/test/status - API and database status

Flask Routes

  • / - Login page
  • /dashboard - Stock market dashboard
  • /users - User management
  • /gallery - Image gallery
  • /upload - Upload images

πŸ—οΈ Project Structure

myproject/
β”œβ”€β”€ app.py                  # Main Flask application
β”œβ”€β”€ fastapi_users.py        # FastAPI user management service
β”œβ”€β”€ db.py                   # Database functions (Django ORM)
β”œβ”€β”€ models.py               # Django model definitions
β”œβ”€β”€ django_settings.py      # Minimal Django configuration
β”œβ”€β”€ init_db.sql             # Database migration script (SQL)
β”œβ”€β”€ apply_migration.py      # Migration runner (Python)
β”œβ”€β”€ ml.py                   # Machine learning utilities
β”œβ”€β”€ templates/              # HTML templates
β”‚   β”œβ”€β”€ base.html
β”‚   β”œβ”€β”€ login.html
β”‚   β”œβ”€β”€ dashboard.html
β”‚   β”œβ”€β”€ users.html
β”‚   β”œβ”€β”€ gallery.html
β”‚   └── upload.html
β”œβ”€β”€ static/                 # Static assets
β”‚   β”œβ”€β”€ css/
β”‚   └── hair_assets/
β”œβ”€β”€ uploads/                # Uploaded files
β”œβ”€β”€ start_fastapi.sh        # FastAPI startup script
└── README.md

πŸ”§ Configuration

Update Login Credentials

Edit app.py:

USERNAME = "admin"
PASSWORD = "123456"

Update Stock Symbols

Edit the fetch_stock_data() function in app.py to customize stock symbols.

πŸ§ͺ Testing

Test FastAPI Endpoints

# Test hello endpoint
curl http://localhost:8000/api/test/hello

# Test user list
curl http://localhost:8000/api/users

# Test calculator
curl -X POST "http://localhost:8000/api/test/calculate?num1=10&num2=5&operation=add"

Test Flask Application

  1. Open browser and navigate to http://localhost:5000
  2. Login with default credentials
  3. Test dashboard, gallery, and user management features

πŸ“¦ Dependencies

Python Packages

  • Flask - Web framework
  • FastAPI - Modern API framework
  • Uvicorn - ASGI server
  • Pydantic - Data validation
  • MySQL Connector - Database connection
  • Pandas - Data manipulation
  • yfinance - Stock market data
  • nsepython - NSE India stock data
  • DeepFace - Face analysis and recognition
  • EasyOCR - Optical character recognition
  • OpenCV - Image processing
  • Pytesseract - OCR engine
  • Scikit-learn - Machine learning

πŸ› Troubleshooting

Database Connection Error

Make sure MySQL is running:

sudo systemctl start mysql  # Linux
brew services start mysql   # macOS

Tesseract Not Found

Install Tesseract OCR and verify installation:

tesseract --version

Port Already in Use

Change the port in app.py or fastapi_users.py:

app.run(debug=True, port=5001)  # Flask
uvicorn.run(app, port=8001)     # FastAPI

CUDA/GPU Warnings

The DeepFace library will show warnings if CUDA/MPS is not available. This is normal and the app will use CPU instead.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is for educational purposes.

πŸ‘¨β€πŸ’» Author

Hiren Kukadiya - GitHub

πŸ™ Acknowledgments

  • Flask and FastAPI communities
  • NSE Python library developers
  • DeepFace and OpenCV contributors

About

Add Fast Apis, Flask

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors