File size: 3,492 Bytes
5def6a0
 
 
 
 
 
61974ad
5def6a0
 
 
 
61974ad
 
 
 
 
5def6a0
6017f4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61974ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
title: Agent Workshop
emoji: 🧠
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: 1.51.0
app_file: app.py
pinned: false
license: mit
tags:
- langchain
- gemini
- ai-agent
- crypto
- huggingface-space
---

# 🪙 Crypto AI Agent (Gemini + LangChain)

This project is a simple **AI-powered crypto assistant** built using **Google’s Gemini model** and **LangChain**.
It can intelligently respond to prompts **and** fetch **real-time cryptocurrency prices** (like Bitcoin and Ethereum) using a live API.


## 🚀 Features**Conversational AI** — Powered by `ChatGoogleGenerativeAI` (Gemini).
✅ **Live Crypto Data** — Fetches real-time prices from the [CoinCap API](https://docs.coincap.io/).
✅ **LangChain Integration** — Uses LangChain’s latest tool architecture (`Tool`).
✅ **Simple Deployment** — Can run directly on **Hugging Face Spaces** or locally.
✅ **Extendable** — Easily add more tools, prompts, or custom logic.


## 🧠 How It Works

1. The user gives a text input (e.g., “Check the Bitcoin price”).
2. The agent detects whether it should:

   * Use a tool (like the `CryptoPriceChecker`), or
   * Use the Gemini model to generate a conversational answer.
3. The result is printed or returned as a response.


## 📂 Project Structure

```
crypto-ai-agent/

├── app.py                # Main application code
├── requirements.txt      # All Python dependencies
└── README.md             # Project documentation
```


## 🧩 Installation

You can run this project locally or deploy it on Hugging Face.

### Option 1: Run Locally

```bash
# Clone the repository
git clone https://github.com/yourusername/crypto-ai-agent.git
cd crypto-ai-agent

# Install dependencies
pip install -r requirements.txt
```

### Option 2: Run in Google Colab

Simply upload `app.py` to your Colab environment and run:

```python
!pip install -r requirements.txt
!python app.py
```

### Option 3: Deploy on Hugging Face Spaces

1. Create a new Space.
2. Choose **“Static / Python (Gradio)”** as your Space type.
3. Upload:

   * `app.py`
   * `requirements.txt`
   * `README.md`
4. Add your **Google API key** in the Hugging Face **Secrets tab** as:

   ```
   GOOGLE_API_KEY=your_api_key_here
   ```


## 🔧 Configuration

You’ll need a valid **Google Generative AI API key** (Gemini).
You can get one from [Google AI Studio](https://makersuite.google.com/app/apikey).

Once you have it, set it as an environment variable:

```bash
export GOOGLE_API_KEY="your_api_key_here"
```

Or, on Hugging Face, use the **“Repository Secrets”** feature.


## 🧾 Example Usage

### In Python:

```python
from app import run_agent

print(run_agent("Check Bitcoin price"))
print(run_agent("What is blockchain?"))
```

### Output:

```
💰 BTC current price: $68,245.12
Blockchain is a distributed ledger technology that allows secure and transparent record-keeping.
```


## 📦 Requirements

See [`requirements.txt`](requirements.txt):

```
langchain>=0.3.0
langchain-google-genai>=0.1.0
langchain-core>=0.3.0
requests>=2.31.0
python-dotenv>=1.0.0
```


## 🧩 Future Enhancements

* Add multiple crypto symbols (e.g., ADA, XRP, DOGE)
* Integrate trading signals or portfolio management
* Add Gradio interface for user input
* Deploy on Hugging Face Space with persistent logs

## 👨‍💻 Author

**Ali Masood**
PhD in Artificial Intelligence | Founder, Zaytrics Pvt Ltd
🚀 Building world-class AI & blockchain solutions.

---