Document Upload
Drop your documents here
or click to browse
from fastapi import FastAPI, UploadFile, File, Form from fastapi.responses import HTMLResponse, JSONResponse from typing import List, Optional import os from .document_loader import DocumentLoader from .chunking import chunk_text from .vector_store import add_to_vector_store, similarity_search from .summarizer import DocumentSummarizer, clean_markdown_formatting # Remove Qwen/transformers imports and model initialization app = FastAPI(title="RAG Document Summarizer", version="1.0.0") print("[INFO] RAG Application starting up...") # Global exception handler to ensure all errors return JSON @app.exception_handler(Exception) async def global_exception_handler(request, exc): print(f"[ERROR] Unhandled exception: {exc}") return JSONResponse( status_code=500, content={"error": f"Internal server error: {str(exc)}"} ) # Remove Qwen2-0.5B model instance for queries (CPU-optimized) def initialize_qwen_model(): """Initialize Qwen2-0.5B model for query responses (CPU-optimized)""" # This function is no longer needed as Qwen model is removed. # Keeping it for now, but it will not initialize the model. print("[INFO] Qwen model is no longer available. Using simulated responses for queries.") return False # Initialize model on startup (non-blocking) @app.on_event("startup") async def startup_event(): print("[INFO] Starting RAG application...") # Initialize model in background to avoid blocking startup import asyncio asyncio.create_task(initialize_qwen_model_async()) async def initialize_qwen_model_async(): """Initialize Qwen model asynchronously to avoid blocking startup""" try: initialize_qwen_model() except Exception as e: print(f"[WARNING] Model initialization failed: {e}") print("[INFO] Application will continue with simulated responses") @app.get("/health") async def health_check(): """Simple health check endpoint""" return {"status": "healthy", "message": "RAG application is running"} @app.get("/", response_class=HTMLResponse) async def read_root(): return """
Advanced Document Processing and Query Resolution
Drop your documents here
or click to browse