/crypto_ai_agent

A conversational AI chatbot built with Python and Flask that can answer general crypto questions

Primary LanguagePythonMIT LicenseMIT

Crypto AI Agent

A conversational AI chatbot built with Python and Flask that can answer general questions, fetch real-time cryptocurrency data (prices, market cap, trading volume, OHLC, top gainers/losers), and even predict future prices using simple machine learning. The agent uses NLTK for natural language processing, CoinGecko API for crypto data, and scikit-learn for basic regression.


Features

  • Conversational Chatbot: Handles greetings, small talk, and fallback responses using NLTK's pattern-matching.
  • Crypto Price Lookup: Get the latest USD price for any supported cryptocurrency.
  • Market Cap & Volume: Query the current market capitalization and trading volume.
  • Top Gainers & Losers: See the top performing and worst performing coins (requires CoinGecko Pro API).
  • OHLC Data: Retrieve Open, High, Low, Close data for a coin.
  • Coin Recommendation: Suggests a coin with the highest market cap and volume.
  • Price Prediction: Uses linear regression on the last 30 days to predict the next day's price.
  • Web Interface: Simple chat UI built with Flask, HTML, and CSS.

Project Structure

.
├── app.py                # Main Flask backend and AI logic
├── requirements.txt      # Python dependencies
├── .env                  # Environment variables (API keys)
├── templates/
│   └── index.html        # Chatbot web interface
├── static/
│   └── css/
│       └── style.css     # UI styling
├── reqs.py               # (Optional) Dependency helper
└── myenv/                # Python virtual environment (not needed for deployment)

Prerequisites

  • Python 3.8+
  • CoinGecko API Key (for some endpoints, especially top gainers/losers)
  • Basic command-line knowledge

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd ai_agent
  2. Create and activate a virtual environment

    python -m venv myenv
    # On Windows:
    myenv\Scripts\activate
    # On macOS/Linux:
    source myenv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Download NLTK data
    In a Python shell:

    import nltk
    nltk.download('punkt')
  5. Set up your .env file
    Create a .env file in the project root:

    COINGECKO_API_KEY=your_api_key_here
    

Running the App

python app.py
  • Visit http://127.0.0.1:5000/ in your browser.
  • Type queries like:
    • price of bitcoin
    • market cap of ethereum
    • trading volume of solana
    • top gainers and losers
    • ohlc of dogecoin
    • predict price of cardano
    • Or just say hello!

Example Queries

  • General:
    hello
    what is your name?

  • Crypto Data:
    price of bitcoin
    market cap of ethereum
    trading volume of solana
    ohlc of dogecoin
    top gainers and losers
    recommend a coin
    predict price of cardano

alt text

Notes

  • Some endpoints (like top gainers/losers) require a CoinGecko Pro API key.
  • The price prediction is a simple linear regression and not financial advice.
  • All environment variables are loaded securely using python-dotenv.

License

This project is for educational purposes. See LICENSE if provided.


References