--- 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.