Spaces:
Running
Running
| title: SmaFit-FastApi | |
| emoji: ๐๏ธ | |
| colorFrom: green | |
| colorTo: blue | |
| sdk: docker | |
| pinned: false | |
| # Capstone Backend API (FastAPI) | |
| This is the Python-based backend that handles authentication (JWT), PostgreSQL database operations (SQLModel/Alembic), API requests, and the RAG Chatbot powered by ChromaDB & Gemini. | |
| ## ๐ ๏ธ Prerequisites | |
| - Python 3.10+ | |
| - PostgreSQL database installed and running locally | |
| ## ๐ Setup Instructions | |
| 1. **Create Virtual Environment** | |
| It is highly recommended to isolate dependencies. Create and activate a virtual environment: | |
| ```bash | |
| # Windows | |
| python -m venv venv | |
| venv\Scripts\activate | |
| # macOS/Linux | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| ``` | |
| 2. **Install Dependencies** | |
| Install FastAPI, SQLModel, Alembic, and all required packages: | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| 3. **Configure Environment Variables** | |
| Sensitive credentials are never pushed to the repository. | |
| - Copy the template file: `cp .env.example .env` | |
| - Open `.env` and fill in your actual PostgreSQL password (`DATABASE_URL`) and generate a `SECRET_KEY`. | |
| - **Note:** The backend will not start if the `SECRET_KEY` is missing! | |
| 4. **Run Database Migrations (Alembic)** | |
| Apply all migrations to set up the database schema: | |
| ```bash | |
| alembic upgrade head | |
| ``` | |
| To create a new migration after changing `models.py`: | |
| ```bash | |
| alembic revision --autogenerate -m "describe_your_change" | |
| alembic upgrade head | |
| ``` | |
| 5. **Setup GenAI & Knowledge Base** | |
| Your `.env` file must contain your `GEMINI_API_KEY`. | |
| Run the ingestion script to populate the ChromaDB vector store with RAG data: | |
| ```bash | |
| python ingest.py | |
| ``` | |
| 6. **Run the Server** | |
| Start the FastAPI development server: | |
| ```bash | |
| fastapi dev main.py | |
| ``` | |
| *(Or alternatively, `uvicorn main:app --reload`)* | |
| Once running, the API will be available at `http://127.0.0.1:8000`. | |
| You can view the interactive auto-generated documentation at `http://127.0.0.1:8000/docs`. | |