Spaces:
Sleeping
Sleeping
File size: 2,797 Bytes
e1ff06f ddf28d3 | 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 | ---
title: Finance-Llama-8B App
emoji: 📈
colorFrom: purple
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
---
# Finance-Llama-8B Gradio App
Two-tab financial agent UI powered by `tarun7r/Finance-Llama-8B`.
- Price Prediction: pulls OHLCV candles from Finnhub and asks the model for a short-term forecast with brief rationale.
- Equity Research Report: fetches Alpha Vantage fundamentals (via RapidAPI) and generates a concise equity research note.
## Model
- Hugging Face model: `tarun7r/Finance-Llama-8B`
- Fine-tuned `unsloth/Meta-Llama-3.1-8B` on `Josephgflowers/Finance-Instruct-500k`
- Loaded with `bitsandbytes` 4-bit quantization for efficient GPU memory usage.
## Tech Stack
- Python 3.12
- Gradio UI
- Transformers + Accelerate + BitsAndBytes (GPU)
- Data: Finnhub (market data), Alpha Vantage via RapidAPI (fundamentals)
## Prerequisites
- NVIDIA GPU with recent CUDA drivers (recommended)
- Python 3.12
- API keys:
- `FINNHUB_API_KEY` from `https://finnhub.io`
- `RAPIDAPI_KEY` with access to Alpha Vantage host `alpha-vantage.p.rapidapi.com`
## Setup
Install dependencies:
```
pip install -r requirements.txt
```
Set environment variables (PowerShell example):
```
$env:FINNHUB_API_KEY = "YOUR_FINNHUB_KEY"
$env:RAPIDAPI_KEY = "YOUR_RAPIDAPI_KEY"
```
Optional server overrides:
```
$env:GRADIO_SERVER_NAME = "0.0.0.0"
$env:GRADIO_SERVER_PORT = "7860"
```
## Run Locally
```
python app.py
```
Open `http://localhost:7860`.
## Hugging Face Spaces (Docker)
This folder includes a `Dockerfile` suitable for Spaces (Docker) runtime. Ensure Secrets are set in the Space:
- `FINNHUB_API_KEY`
- `RAPIDAPI_KEY`
The app will start on port 7860 by default.
## How It Works
- Price Prediction tab
- Fetch last N candles from Finnhub.
- Build a compact JSON context and prompt the LLM to provide a short-term view and bullet-point drivers.
- Equity Research Report tab
- Call Alpha Vantage `OVERVIEW` via RapidAPI host `alpha-vantage.p.rapidapi.com`.
- Prompt the LLM to synthesize a research note: business summary, performance, profitability, leverage, valuation, risks, and a Buy/Hold/Sell view.
## Troubleshooting
- CUDA/torch version mismatch: use compatible PyTorch wheels for your environment or the provided Dockerfile on Spaces.
- `bitsandbytes` load errors: ensure GPU is available; for CPUs, remove 4-bit loading and use standard FP16/FP32 (will be slower, higher memory).
- API errors or empty responses: verify `FINNHUB_API_KEY` and `RAPIDAPI_KEY`, and check provider rate limits.
## Notes
- Respect provider rate limits and terms of use.
- Outputs are model-generated and for research/education purposes only, not financial advice.
|