# nogibjj/astrology-bot architecture

> Architecture diagram of the GitHub repository nogibjj/astrology-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nogibjj/astrology-bot
- Repository: https://github.com/nogibjj/astrology-bot

## Overview

##### Project Type and Purpose
- The project is essentially a chatbot application focused on astrological readings (horoscope and tarot) that leverages a fine-tuned LLaMA-2-7B language model.
- It uses a RAG pipeline: text data is chunked, embedded via a BGE-Large model, indexed (with Pinecone as mentioned in the README), and then queried to retrieve contextual text.
- The UI is deployed (via Streamlit) and also includes a web interface component (with HTML/CSS/JS under the “interface” folder).

##### Breaking Down the File Structure into Major Components
- Data Layer:
- Data files are in the “data” directory (csv files, parquet of embeddings, notebooks for webscraping).
- This is where horoscope and tarot data is stored and pre-processed.

- RAG Pipeline Components:
- The “RAG” folder houses scripts for chunking text (chunk_data.py), indexing data (index_data.py), orchestrating the main pipeline (main.py), and miscellaneous utilities (utils.py).
- This layer performs the key steps: chunking, embedding text data (can be linked to models under the “model” directory), and managing retrieval.

- Model Module:
- The “model” directory includes code related to creating embeddings (embedding_model.py) and running/inferencing (inference_model.py). There’s also a notebook for fine-tuning LLaMA-2-7B.
- This module shows the integration of the chosen models with the RAG system.

- Interface / Frontend:
- The “interface” directory contains the code for handling responses (get_answer_horoscope.py, get_response.py, inference.py) along with the HTML, JS, and CSS files to render the UI.
- A separate UI.py at the root level and a .streamlit folder (with deployment config files like secrets.toml) indicate that a Streamlit application powers the user interface.

- Deployment and Configuration:
- Files like .gitignore, LICENSE, USE_POLICY.md, and requirements.txt represent standard configuration and deployment support.
- The README and notebooks indicate how to test and run the experiments.

##### Key Relationships and Interactions
- Data ingestion (via web scrapers and CSVs) flows from the “data” directory into the processing pipeline in the RAG layer.
- The RAG component processes raw text data by executing chunking (with “chunk_data.py”), indexing (through “index_data.py”), and then feeding into the model.
- The embedding and inference occur in the “model” module using embedding functions and the fine-tuned LLaMA-2-7B model.
- End-user queries are sent to the UI (handled by Streamlit and an HTML/CSS/JS front-end) which communicates with the “interface” scripts to route the request to the inference backend.
- In production, configuration and secrets (in .streamlit) ensure secure and correct deployments, while the README explains the pipeline.

##### Detailed Implementation Steps
- Sketch the overall layout starting from the data acquisition stage (data scraping and stored CSVs) leading into the RAG system.
- Step of the pipeline:
- Data is chunked (chunk_data.py) and indexed (index_data.py).
- The embedding layer (embedding_model.py) transforms text data for similarity search.
- The query processing component replicates these embedding steps to retrieve context via cosine similarity.
- The inference module (inference_model.py) with LLaMA-2-7B fine-tuning produces and post-processes the final answer.
- Separate the user-facing side:
- The Streamlit deployment and the web interface components (HTML, JS, CSS) form a distinct group connecting to the processing backend.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        A["Data Files (CSVs & Notebooks)"]:::data
    end

    %% RAG Pipeline Components
    subgraph "RAG Pipeline"
        direction TB
        B1["Chunking Module (chunk_data.py)"]:::rag
        B2["Indexing Module (index_data.py)"]:::rag
        B3["Main Orchestration (main.py)"]:::rag
        B4["Utilities (utils.py)"]:::rag
    end

    %% Model Module
    subgraph "Model Module"
        direction TB
        C1["Embedding Model (embedding_model.py)"]:::model
        C2["Inference Model (inference_model.py)"]:::model
        C3["Fine-tuning Notebook (fine-tune-llama2-7b.ipynb)"]:::model
    end

    %% External Service: Pinecone
    D["Pinecone\n(Vector Index)"]:::external

    %% User Interface / Frontend
    subgraph "User Interface"
        direction TB
        E1["Streamlit UI (UI.py)"]:::ui
        E2[".streamlit Config (secrets.toml)"]:::ui
        subgraph "Web Interface Components"
            direction TB
            E3["get_answer_horoscope.py"]:::ui
            E4["get_response.py"]:::ui
            E5["index.html"]:::ui
            E6["inference.py"]:::ui
            E7["script.js"]:::ui
            E8["styles.css"]:::ui
        end
    end

    %% Connections
    A -->|"pre-processing"| B1
    B1 -->|"chunked data"| B2
    B2 -->|"indexed data"| B3
    B3 -->|"retrieve context"| C2
    C1 -->|"embeds data"| C2
    B2 ---|"store_embeddings"| D

    %% UI interactions
    E1 -->|"user query"| C2
    C2 -->|"response"| E1

    %% Styles
    classDef data fill:#FFEEAA,stroke:#DAA520,stroke-width:2px;
    classDef rag fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef model fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef ui fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef external fill:#CFD8DC,stroke:#607D8B,stroke-width:2px;

    %% Click Events for Data Layer
    click A "https://github.com/nogibjj/astrology-bot/tree/main/data/"

    %% Click Events for RAG Pipeline Components
    click B1 "https://github.com/nogibjj/astrology-bot/blob/main/RAG/chunk_data.py"
    click B2 "https://github.com/nogibjj/astrology-bot/blob/main/RAG/index_data.py"
    click B3 "https://github.com/nogibjj/astrology-bot/blob/main/RAG/main.py"
    click B4 "https://github.com/nogibjj/astrology-bot/blob/main/RAG/utils.py"

    %% Click Events for Model Module
    click C1 "https://github.com/nogibjj/astrology-bot/blob/main/model/embedding_model.py"
    click C2 "https://github.com/nogibjj/astrology-bot/blob/main/model/inference_model.py"
    click C3 "https://github.com/nogibjj/astrology-bot/blob/main/model/fine-tune-llama2-7b.ipynb"

    %% Click Events for UI / Frontend
    click E1 "https://github.com/nogibjj/astrology-bot/blob/main/UI.py"
    click E2 "https://github.com/nogibjj/astrology-bot/tree/main/.streamlit/"
    click E3 "https://github.com/nogibjj/astrology-bot/blob/main/interface/get_answer_horoscope.py"
    click E4 "https://github.com/nogibjj/astrology-bot/blob/main/interface/get_response.py"
    click E5 "https://github.com/nogibjj/astrology-bot/blob/main/interface/index.html"
    click E6 "https://github.com/nogibjj/astrology-bot/blob/main/interface/inference.py"
    click E7 "https://github.com/nogibjj/astrology-bot/blob/main/interface/script.js"
    click E8 "https://github.com/nogibjj/astrology-bot/blob/main/interface/styles.css"
```
