Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException | |
| from rag_service import rag_service | |
| app = FastAPI( | |
| title="Multi-Modal RAG API", | |
| description="API for querying documents with text and images", | |
| version="1.0.0" | |
| ) | |
| async def root(): | |
| return {"message": "Multi-Modal RAG API is running"} | |
| async def ask_question(question: str): | |
| """ | |
| Ask a question to the RAG system | |
| """ | |
| try: | |
| response = rag_service.ask_question(question) | |
| return { | |
| "question": question, | |
| "response": response, | |
| "status": "success" | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Error processing question: {str(e)}") | |
| async def health_check(): | |
| """ | |
| Health check endpoint | |
| """ | |
| try: | |
| # Check if vectorstore is accessible | |
| count = rag_service.vectorstore._collection.count() | |
| return { | |
| "status": "healthy", | |
| "vectorstore_documents": count, | |
| "docstore_documents": len(rag_service.store.store) | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Health check failed: {str(e)}") | |