Spaces:
Running
Running
Iniitial commit: CRYPTO_ANALYST_AGENT
Browse files- .gitignore +20 -0
- README.md +86 -1
- app.py +1 -1
- tools/analytics_tool.py +14 -14
- tools/historical_data_tool.py +1 -1
- tools/sentiment_tool.py +3 -3
.gitignore
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
|
| 5 |
+
# gradio artifacts
|
| 6 |
+
.gradio/
|
| 7 |
+
|
| 8 |
+
# certs / keys
|
| 9 |
+
*.pem
|
| 10 |
+
*.key
|
| 11 |
+
*.crt
|
| 12 |
+
|
| 13 |
+
# env/secrets
|
| 14 |
+
.env
|
| 15 |
+
*.env
|
| 16 |
+
|
| 17 |
+
# OS/IDE
|
| 18 |
+
.DS_Store
|
| 19 |
+
.vscode/
|
| 20 |
+
.idea/
|
README.md
CHANGED
|
@@ -11,4 +11,89 @@ license: apache-2.0
|
|
| 11 |
short_description: Collect data, analyze and report on crypto
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
short_description: Collect data, analyze and report on crypto
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Crypto Analyst Agent 📈
|
| 15 |
+
|
| 16 |
+
An interactive **Gradio** app that collects crypto market information, runs analysis (pricing + indicators + sentiment), and generates a concise report to support research and decision-making.
|
| 17 |
+
|
| 18 |
+
> ⚠️ Educational project only — not financial advice.
|
| 19 |
+
|
| 20 |
+
## What it does
|
| 21 |
+
- **Fetches market data** (price, market cap, volume, etc.)
|
| 22 |
+
- **Pulls historical data** for trend/returns analysis
|
| 23 |
+
- **Runs analytics** (basic performance + volatility-style metrics depending on configuration)
|
| 24 |
+
- **Incorporates sentiment signals** (tool-based sentiment module)
|
| 25 |
+
- **Generates a structured report** in a single workflow
|
| 26 |
+
|
| 27 |
+
## Project structure
|
| 28 |
+
```text
|
| 29 |
+
.
|
| 30 |
+
├── app.py
|
| 31 |
+
├── tools/
|
| 32 |
+
│ ├── __init__.py
|
| 33 |
+
│ ├── market_data.py
|
| 34 |
+
│ ├── historical_data_tool.py
|
| 35 |
+
│ ├── analytics_tool.py
|
| 36 |
+
│ └── sentiment_tool.py
|
| 37 |
+
├── requirements.txt
|
| 38 |
+
└── README.md
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Getting started (local)
|
| 42 |
+
### 1. Clone and install
|
| 43 |
+
```bash
|
| 44 |
+
git clone https://github.com/cicboy80/CRYPTO_ANALYST_AGENT.git
|
| 45 |
+
cd CRYPTO_ANALYST_AGENT
|
| 46 |
+
python -m venv .venv
|
| 47 |
+
source .venv/bin/activate # macOS/Linux
|
| 48 |
+
# .venv\Scripts\activate # Windows
|
| 49 |
+
pip install -r requirements.txt
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### 2. Environment variables
|
| 53 |
+
|
| 54 |
+
This project uses API keys for **OpenAI** and **CoinGecko**.
|
| 55 |
+
|
| 56 |
+
Set these as environment variables (recommended), or create a local `.env` file (**do not commit it**).
|
| 57 |
+
|
| 58 |
+
Required:
|
| 59 |
+
- `OPENAI_API_KEY`
|
| 60 |
+
- `COINGECKO_API_KEY`
|
| 61 |
+
|
| 62 |
+
Example:
|
| 63 |
+
```bash
|
| 64 |
+
export OPENAI_API_KEY="..."
|
| 65 |
+
export COINGECKO_API_KEY="..."
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### 3. Run the app
|
| 69 |
+
```bash
|
| 70 |
+
python app.py
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Then open the local Gradio URL printed in the terminal.
|
| 74 |
+
|
| 75 |
+
## Hugging Face Spaces: Secrets setup
|
| 76 |
+
Add the following under **Settings → Secrets** in your Space:
|
| 77 |
+
- `OPENAI_API_KEY`
|
| 78 |
+
- `COINGECKO_API_KEY`
|
| 79 |
+
|
| 80 |
+
## Deploying on Hugging Face Spaces
|
| 81 |
+
|
| 82 |
+
1. Create a new **Gradio** Space
|
| 83 |
+
2. Add your repo files (`app.py`, `tools/`, `requirements.txt`, `README.md`)
|
| 84 |
+
3. Add required keys under Settings → Secrets
|
| 85 |
+
|
| 86 |
+
## Notes on security
|
| 87 |
+
|
| 88 |
+
- Never commit secrets (API keys, tokens, .env, certificates)
|
| 89 |
+
- Keep credentials in Hugging Face Secrets (or your cloud provider’s secret manager)
|
| 90 |
+
|
| 91 |
+
## Roadmap
|
| 92 |
+
|
| 93 |
+
- Add caching for API responses
|
| 94 |
+
- Expand analytics (risk metrics, drawdown, rolling volatility)
|
| 95 |
+
- Improve reporting format (markdown + export)
|
| 96 |
+
|
| 97 |
+
## License
|
| 98 |
+
|
| 99 |
+
Apache-2.0
|
app.py
CHANGED
|
@@ -256,7 +256,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
|
| 256 |
label="Historical Lookback (days)"
|
| 257 |
)
|
| 258 |
|
| 259 |
-
#
|
| 260 |
run_button = gr.Button("🚀 Run Full Analysis", variant="primary")
|
| 261 |
|
| 262 |
report_output = gr.Markdown(label="📊 Intelligence Report")
|
|
|
|
| 256 |
label="Historical Lookback (days)"
|
| 257 |
)
|
| 258 |
|
| 259 |
+
# button
|
| 260 |
run_button = gr.Button("🚀 Run Full Analysis", variant="primary")
|
| 261 |
|
| 262 |
report_output = gr.Markdown(label="📊 Intelligence Report")
|
tools/analytics_tool.py
CHANGED
|
@@ -22,9 +22,9 @@ class AnalyticsTool(BaseTool):
|
|
| 22 |
|
| 23 |
def _run(self, market_data: dict, historical_data: dict, sentiment_data: dict) -> dict:
|
| 24 |
try:
|
| 25 |
-
#
|
| 26 |
-
# 1) Extract fields
|
| 27 |
-
#
|
| 28 |
|
| 29 |
price = market_data.get("latest_price")
|
| 30 |
pct_change = historical_data.get("pct_change")
|
|
@@ -42,9 +42,9 @@ class AnalyticsTool(BaseTool):
|
|
| 42 |
|
| 43 |
sentiment = sentiment.lower()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
# 2) Sentiment strength & confidence
|
| 47 |
-
#
|
| 48 |
|
| 49 |
# Pull from SentimentTool if present
|
| 50 |
sentiment_strength = sentiment_data.get("sentiment_strength")
|
|
@@ -68,18 +68,18 @@ class AnalyticsTool(BaseTool):
|
|
| 68 |
# Effective weighted sentiment
|
| 69 |
effective_sentiment = sentiment_strength * sentiment_confidence
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
# 3) Alignment logic
|
| 73 |
-
#
|
| 74 |
|
| 75 |
aligned = (
|
| 76 |
(trend == "upward" and effective_sentiment > 0.2) or
|
| 77 |
(trend == "downward" and effective_sentiment < -0.2)
|
| 78 |
)
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
# 4) Composite score
|
| 82 |
-
#
|
| 83 |
|
| 84 |
score = (
|
| 85 |
(pct_change / 10) + # Trend effect
|
|
@@ -90,9 +90,9 @@ class AnalyticsTool(BaseTool):
|
|
| 90 |
# Bound between [-1, 1]
|
| 91 |
score = round(max(-1, min(1, score)), 2)
|
| 92 |
|
| 93 |
-
#
|
| 94 |
# 5) Final structured output
|
| 95 |
-
#
|
| 96 |
|
| 97 |
return {
|
| 98 |
"price": price,
|
|
|
|
| 22 |
|
| 23 |
def _run(self, market_data: dict, historical_data: dict, sentiment_data: dict) -> dict:
|
| 24 |
try:
|
| 25 |
+
# ------------------------------------------------------------
|
| 26 |
+
# 1) Extract fields from structured tool outputs
|
| 27 |
+
# ------------------------------------------------------------
|
| 28 |
|
| 29 |
price = market_data.get("latest_price")
|
| 30 |
pct_change = historical_data.get("pct_change")
|
|
|
|
| 42 |
|
| 43 |
sentiment = sentiment.lower()
|
| 44 |
|
| 45 |
+
# ------------------------------------------------------------
|
| 46 |
+
# 2) Sentiment strength & confidence
|
| 47 |
+
# ------------------------------------------------------------
|
| 48 |
|
| 49 |
# Pull from SentimentTool if present
|
| 50 |
sentiment_strength = sentiment_data.get("sentiment_strength")
|
|
|
|
| 68 |
# Effective weighted sentiment
|
| 69 |
effective_sentiment = sentiment_strength * sentiment_confidence
|
| 70 |
|
| 71 |
+
# ------------------------------------------------------------
|
| 72 |
+
# 3) Alignment logic
|
| 73 |
+
# ------------------------------------------------------------
|
| 74 |
|
| 75 |
aligned = (
|
| 76 |
(trend == "upward" and effective_sentiment > 0.2) or
|
| 77 |
(trend == "downward" and effective_sentiment < -0.2)
|
| 78 |
)
|
| 79 |
|
| 80 |
+
# ------------------------------------------------------------
|
| 81 |
+
# 4) Composite score
|
| 82 |
+
# ------------------------------------------------------------
|
| 83 |
|
| 84 |
score = (
|
| 85 |
(pct_change / 10) + # Trend effect
|
|
|
|
| 90 |
# Bound between [-1, 1]
|
| 91 |
score = round(max(-1, min(1, score)), 2)
|
| 92 |
|
| 93 |
+
# ------------------------------------------------------------
|
| 94 |
# 5) Final structured output
|
| 95 |
+
# ------------------------------------------------------------
|
| 96 |
|
| 97 |
return {
|
| 98 |
"price": price,
|
tools/historical_data_tool.py
CHANGED
|
@@ -82,7 +82,7 @@ class HistoricalDataTool(BaseTool):
|
|
| 82 |
"pct_change": round(pct_change, 2),
|
| 83 |
"volatility_pct": round(volatility, 2),
|
| 84 |
"trend": trend,
|
| 85 |
-
"price_history": history,
|
| 86 |
}
|
| 87 |
|
| 88 |
except Exception as e:
|
|
|
|
| 82 |
"pct_change": round(pct_change, 2),
|
| 83 |
"volatility_pct": round(volatility, 2),
|
| 84 |
"trend": trend,
|
| 85 |
+
"price_history": history,
|
| 86 |
}
|
| 87 |
|
| 88 |
except Exception as e:
|
tools/sentiment_tool.py
CHANGED
|
@@ -30,9 +30,9 @@ class SentimentInput(BaseModel):
|
|
| 30 |
)
|
| 31 |
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
# SENTIMENT TOOL
|
| 35 |
-
#
|
| 36 |
class SentimentTool(BaseTool):
|
| 37 |
"""
|
| 38 |
Fetches recent crypto news via Serper and produces aggregated sentiment
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
|
| 33 |
+
# -------------------------------------------------------------------
|
| 34 |
+
# SENTIMENT TOOL
|
| 35 |
+
# -------------------------------------------------------------------
|
| 36 |
class SentimentTool(BaseTool):
|
| 37 |
"""
|
| 38 |
Fetches recent crypto news via Serper and produces aggregated sentiment
|