Spaces:
Runtime error
Runtime error
Deploy full stack Lumina Self-RAG system to Hugging Face Spaces
Browse files- .dockerignore +10 -0
- .gitignore +2 -2
- Dockerfile +40 -0
- README.md +35 -0
- chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/data_level0.bin +3 -0
- chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/header.bin +3 -0
- chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/length.bin +3 -0
- chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/link_lists.bin +0 -0
- chroma_db/chroma.sqlite3 +3 -0
- requirements.txt +1 -0
- self_rag_agent.py +14 -2
- university-advisor-ui/src/services/api.ts +1 -1
- vector_store_fallback.pkl +3 -0
.dockerignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.git
|
| 2 |
+
.gitignore
|
| 3 |
+
.env
|
| 4 |
+
venv
|
| 5 |
+
__pycache__
|
| 6 |
+
university-advisor-ui/node_modules
|
| 7 |
+
university-advisor-ui/dist
|
| 8 |
+
*.pyc
|
| 9 |
+
.ipynb_checkpoints
|
| 10 |
+
scratch
|
.gitignore
CHANGED
|
@@ -3,8 +3,8 @@ venv/
|
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
.env
|
| 6 |
-
vector_store_fallback.pkl
|
| 7 |
-
chroma_db/
|
| 8 |
|
| 9 |
# Frontend
|
| 10 |
university-advisor-ui/node_modules/
|
|
|
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
.env
|
| 6 |
+
# vector_store_fallback.pkl
|
| 7 |
+
# chroma_db/
|
| 8 |
|
| 9 |
# Frontend
|
| 10 |
university-advisor-ui/node_modules/
|
Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stage 1: Build the frontend
|
| 2 |
+
FROM node:20-slim AS build-stage
|
| 3 |
+
WORKDIR /ui-build
|
| 4 |
+
COPY university-advisor-ui/package*.json ./
|
| 5 |
+
RUN npm install
|
| 6 |
+
COPY university-advisor-ui/ ./
|
| 7 |
+
RUN npm run build
|
| 8 |
+
|
| 9 |
+
# Stage 2: Python environment
|
| 10 |
+
FROM python:3.11-slim
|
| 11 |
+
|
| 12 |
+
# Install system dependencies for sentence-transformers/chromadb if needed
|
| 13 |
+
RUN apt-get update && apt-get install -y \
|
| 14 |
+
build-essential \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
RUN useradd -m -u 1000 user
|
| 18 |
+
USER user
|
| 19 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 20 |
+
WORKDIR /app
|
| 21 |
+
|
| 22 |
+
# Install dependencies
|
| 23 |
+
COPY --chown=user requirements.txt .
|
| 24 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 25 |
+
|
| 26 |
+
# Copy backend code and data
|
| 27 |
+
COPY --chown=user . .
|
| 28 |
+
|
| 29 |
+
# Copy built frontend from build-stage to 'static' folder
|
| 30 |
+
COPY --chown=user --from=build-stage /ui-build/dist /app/static
|
| 31 |
+
|
| 32 |
+
# Ensure data directories exist and have correct permissions
|
| 33 |
+
# (COPY --chown handles this mostly, but good to be explicit if they are created at runtime)
|
| 34 |
+
# RUN mkdir -p chroma_db data
|
| 35 |
+
|
| 36 |
+
# Expose port 7860
|
| 37 |
+
EXPOSE 7860
|
| 38 |
+
|
| 39 |
+
# Run the app
|
| 40 |
+
CMD ["python", "self_rag_agent.py"]
|
README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Lumina Intelligent University Advisor
|
| 3 |
+
emoji: 🎓
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Lumina: The Intelligent University Advisor
|
| 12 |
+
A production-grade Self-RAG advisory system built with LangGraph, Groq, and React.
|
| 13 |
+
|
| 14 |
+
## Features
|
| 15 |
+
- **Self-RAG Architecture**: Real-time reflection on retrieval relevance and hallucination detection.
|
| 16 |
+
- **High Performance**: Powered by Groq Llama 3.3 70B for near-instant reasoning.
|
| 17 |
+
- **Glassmorphic UI**: Transparent pipeline visualization showing the agent's internal reasoning steps.
|
| 18 |
+
- **Robust Knowledge Base**: Grounded in official university catalogs and policies.
|
| 19 |
+
|
| 20 |
+
## Environment Variables
|
| 21 |
+
To run this Space, you need to set the following secrets in your Space settings:
|
| 22 |
+
- `GROQ_API_KEY`: Your Groq API key.
|
| 23 |
+
- `TAVILY_API_KEY`: Your Tavily API key for web search fallback.
|
| 24 |
+
- `GOOGLE_API_KEY`: (Optional) If using Google Generative AI components.
|
| 25 |
+
|
| 26 |
+
## Local Development
|
| 27 |
+
```bash
|
| 28 |
+
# Install dependencies
|
| 29 |
+
pip install -r requirements.txt
|
| 30 |
+
cd university-advisor-ui && npm install && npm run build
|
| 31 |
+
cd ..
|
| 32 |
+
|
| 33 |
+
# Run the backend (it will serve the built UI from /static)
|
| 34 |
+
python self_rag_agent.py
|
| 35 |
+
```
|
chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/data_level0.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b3a8b17a80a92d890b6248df2c8efdcacb6584977726972b18112a070e701f74
|
| 3 |
+
size 1676000
|
chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/header.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e87a1dc8bcae6f2c4bea6d5dd5005454d4dace8637dae29bff3c037ea771411e
|
| 3 |
+
size 100
|
chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/length.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc19b1997119425765295aeab72d76faa6927d4f83985d328c26f20468d6cc76
|
| 3 |
+
size 4000
|
chroma_db/997e39d6-02a7-4a01-ae7d-452ccb400534/link_lists.bin
ADDED
|
File without changes
|
chroma_db/chroma.sqlite3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:998b476044f0719eb63fa274c4bf8d84cd36c5f029369ea5408d17abc7c3aa49
|
| 3 |
+
size 434176
|
requirements.txt
CHANGED
|
@@ -12,3 +12,4 @@ sentence-transformers==3.0.1
|
|
| 12 |
langchain-huggingface==0.0.3
|
| 13 |
fastapi==0.111.0
|
| 14 |
uvicorn==0.30.1
|
|
|
|
|
|
| 12 |
langchain-huggingface==0.0.3
|
| 13 |
fastapi==0.111.0
|
| 14 |
uvicorn==0.30.1
|
| 15 |
+
aiofiles==24.1.0
|
self_rag_agent.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List, Optional
|
| 5 |
import uvicorn
|
|
@@ -107,5 +109,15 @@ async def pipeline_status():
|
|
| 107 |
async def run_pipeline():
|
| 108 |
return {"status": "skipped", "message": "Pipeline logic not applicable to RAG Agent"}
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
if __name__ == "__main__":
|
| 111 |
-
uvicorn.run("self_rag_agent:app_api", host="0.0.0.0", port=
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from fastapi.responses import FileResponse
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from typing import List, Optional
|
| 7 |
import uvicorn
|
|
|
|
| 109 |
async def run_pipeline():
|
| 110 |
return {"status": "skipped", "message": "Pipeline logic not applicable to RAG Agent"}
|
| 111 |
|
| 112 |
+
# Serve Frontend - This MUST be at the end
|
| 113 |
+
# We assume the built frontend is in a directory named 'static'
|
| 114 |
+
if os.path.exists("static"):
|
| 115 |
+
app_api.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 116 |
+
|
| 117 |
+
@app_api.get("/{full_path:path}")
|
| 118 |
+
async def serve_frontend(full_path: str):
|
| 119 |
+
# Fallback for SPA routing
|
| 120 |
+
return FileResponse("static/index.html")
|
| 121 |
+
|
| 122 |
if __name__ == "__main__":
|
| 123 |
+
uvicorn.run("self_rag_agent:app_api", host="0.0.0.0", port=7860, reload=False)
|
university-advisor-ui/src/services/api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { WindowMemoryItem } from "../types"
|
| 2 |
|
| 3 |
-
const API_BASE = "
|
| 4 |
const MOCK_MODE = false // Set to false when backend is running
|
| 5 |
|
| 6 |
export interface ChatRequest {
|
|
|
|
| 1 |
import { WindowMemoryItem } from "../types"
|
| 2 |
|
| 3 |
+
const API_BASE = ""
|
| 4 |
const MOCK_MODE = false // Set to false when backend is running
|
| 5 |
|
| 6 |
export interface ChatRequest {
|
vector_store_fallback.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d713c037e0de3999c672d5c6a0d5059146e5a71c060ae47e0ab69d7bf7c465de
|
| 3 |
+
size 82382
|