CoolFace
Apppublic

Ayshh/rag-document-intelligence

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
main.py47 linesDownload Raw Back to root
1from fastapi import FastAPI, UploadFile, File2from fastapi.responses import JSONResponse3from pydantic import BaseModel4import os5 6app = FastAPI(7    title="RAG Document Intelligence System",8    description="Production RAG pipeline: PDF upload → FAISS vector search → LLaMA3 answer generation via Groq",9    version="1.0.0"10)11 12class QueryRequest(BaseModel):13    question: str14    top_k: int = 315 16@app.get("/")17def root():18    return {19        "app": "RAG Document Intelligence System",20        "author": "Mohammad Ayesha Summaiyya",21        "github": "https://github.com/Ayesha037",22        "endpoints": ["/upload", "/query", "/health", "/docs"]23    }24 25@app.get("/health")26def health():27    return {"status": "running"}28 29@app.post("/upload")30async def upload_pdf(file: UploadFile = File(...)):31    if not file.filename.endswith(".pdf"):32        return JSONResponse(status_code=400, content={"error": "Only PDF files accepted"})33    contents = await file.read()34    return {35        "message": f"Received '{file.filename}' ({len(contents)} bytes). Connect your RAG pipeline here.",36        "filename": file.filename,37        "size_bytes": len(contents)38    }39 40@app.post("/query")41async def query(request: QueryRequest):42    return {43        "question": request.question,44        "answer": "Connect your LangChain + Groq pipeline here to generate answers.",45        "top_k": request.top_k,46        "sources": ["doc_chunk_1", "doc_chunk_2", "doc_chunk_3"]47    }