Skip to content

TalhaRana01/secure_ai-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Secure AI Chatbot

A professional chatbot application with JWT authentication built using FastAPI, Streamlit, and OpenAI GPT-3.5.

Python FastAPI OpenAI License

🌟 Features

  • πŸ” Secure JWT Authentication - Protected API endpoints
  • πŸ€– AI-Powered Chat - OpenAI GPT-3.5 Turbo integration
  • 🎨 Modern UI - Beautiful Streamlit frontend interface
  • πŸ’¬ Real-time Chat - Interactive conversation experience
  • πŸ›‘οΈ Error Handling - Robust error management
  • πŸ“± Responsive Design - Works on all devices

πŸš€ Quick Demo

Chatbot Demo Secure chat interface with authentication

πŸ› οΈ Technologies Used

Technology Purpose
FastAPI Backend API & Authentication
Streamlit Frontend User Interface
OpenAI AI Chat Integration
JWT Token-based Authentication
Bcrypt Password Hashing
Pydantic Data Validation

πŸ”§ Setup Instructions

Prerequisites

  • Python 3.8 or higher
  • OpenAI API Key

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/secure-ai-chatbot.git
cd secure-ai-chatbot
  1. Create virtual environment:
python -m venv venv

# Windows
venv\Scripts\activate

# Mac/Linux
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Setup environment variables:
# Copy template
cp .env.example .env

# Windows
copy .env.example .env
  1. Configure your OpenAI API Key: Edit the .env file and add your API key:
OPENAI_API_KEY=sk-your-openai-api-key-here

Running the Application

Terminal 1 - Start Backend Server:

uvicorn main:app --reload --port 8000

Terminal 2 - Start Frontend Interface:

streamlit run frontend.py

Access the Application

πŸ” Default Credentials

Field Value
Username admin
Password admin123

Note: Change these credentials in production

🎨 User Interface

Login Screen

Login Screen Secure authentication interface

Chat Interface

Chat Interface Real-time AI chat experience

Settings Panel

Settings Customizable API settings

πŸ“ Project Structure

secure-ai-chatbot/
β”œβ”€β”€ main.py              # FastAPI backend with authentication
β”œβ”€β”€ frontend.py          # Streamlit frontend interface
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ .env.example         # Environment variables template
β”œβ”€β”€ .gitignore          # Git ignore file
β”œβ”€β”€ README.md           # Project documentation
└── screenshots/        # Demo images
    β”œβ”€β”€ chat_demo.png
    β”œβ”€β”€ login_screen.png
    β”œβ”€β”€ chat_interface.png
    └── settings_panel.png

πŸ”’ Security Features

  • JWT Token Authentication
  • Bcrypt Password Hashing
  • Protected API Endpoints
  • Secure Session Management
  • Input Validation

🎯 API Endpoints

Endpoint Method Description
/ GET Health check
/token POST Authentication endpoint
/chat POST AI chat endpoint
/users/me/ GET User profile endpoint

πŸš€ Deployment Options

Heroku Deployment

# Procfile
web: uvicorn main:app --host 0.0.0.0 --port $PORT

Docker Deployment (Optional)

FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

πŸ“ˆ Performance Metrics

  • Response Time: < 2 seconds
  • Authentication: JWT token-based
  • Scalability: Ready for production
  • Security: Industry-standard practices

πŸ› Troubleshooting

Common Issues

  1. Authentication Error

    • Check .env file contains valid API key
    • Verify username/password credentials
  2. Module Not Found

    pip install -r requirements.txt
  3. Port Already in Use

    # Change port
    uvicorn main:app --reload --port 8001

Debug Mode

# Enable debug logging
export DEBUG=True
uvicorn main:app --reload --log-level debug

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • FastAPI - Modern Python web framework
  • Streamlit - Frontend framework
  • OpenAI - AI model provider
  • JWT - Authentication standard

πŸ“ž Support

For support, email [mtalharana093@gmail.com] or open an issue on GitHub.


⭐ If you find this project helpful, please consider giving it a star on GitHub!

GitHub stars


Built with ❀️ by Talha Rana

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages