This project is a sophisticated file management system that combines modern web technologies with AI capabilities. It features a React-based frontend and a FastAPI backend, providing a seamless experience for file management, PDF processing, and AI-powered document interaction.
https://drive.google.com/file/d/1DVKwiVIc6HVCcfoEITgRKb1THtIgFS_5/view?usp=sharing
- Built with React and TypeScript
- Uses Tailwind CSS for styling
- Features a modern, responsive UI with a collapsible sidebar
- Implements real-time chat interface for document interaction
- FastAPI-based REST API
- SQLAlchemy for database management
- PDF processing capabilities using PyMuPDF
- Vector store integration for AI features
- CORS middleware for secure cross-origin requests
# Backend file handling
@app.post("/api/files/upload")
async def upload_file(file: UploadFile):
# File processing logic
return {"filename": file.filename, "status": "success"}def extract_text_from_pdf(pdf_data: bytes) -> Dict[str, any]:
"""
Extract text content from a PDF file with metadata and page information
"""
pdf_document = fitz.open(stream=pdf_data, filetype="pdf")
metadata = pdf_document.metadata
page_count = len(pdf_document)
# ... text extraction logicThe system includes an AI-powered chat interface that allows users to interact with their documents:
<ChatInterface
selectedFile={selectedFile}
chatHistory={chatHistory}
onSendMessage={handleSendMessage}
isLoading={isChatLoading}
userProfileImage={userProfileImage}
/>Challenge: Efficiently extracting and processing large PDF files while maintaining performance. Solution: Implemented streaming processing and caching mechanisms:
# PDF processing with error handling
try:
pdf_document = fitz.open(stream=pdf_data, filetype="pdf")
# Process pages individually
for page_num in range(page_count):
page = pdf_document[page_num]
text = page.get_text()
# Store in vector database
except Exception as e:
handle_error(e)Challenge: Managing real-time communication between frontend and backend. Solution: Implemented WebSocket connections and state management:
const handleSendMessage = async (message) => {
try {
setIsLoading(true);
const response = await sendMessageToBackend(message);
updateChatHistory(response);
} catch (error) {
handleError(error);
} finally {
setIsLoading(false);
}
};Challenge: Handling large file uploads and maintaining file integrity. Solution: Implemented chunked uploads and validation:
@app.post("/api/files/upload")
async def upload_file(file: UploadFile):
try:
# Validate file type and size
if not is_valid_file(file):
raise HTTPException(status_code=400, detail="Invalid file")
# Process file in chunks
contents = await file.read()
# Store in database
return {"status": "success"}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))The system implements comprehensive error handling at multiple levels:
- Frontend Error Handling:
{error && (
<div className="bg-red-50 border-l-4 border-red-400 p-4">
<div className="flex">
<div className="ml-3">
<p className="text-sm text-red-700">{error}</p>
</div>
</div>
</div>
)}- Backend Error Handling:
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
return JSONResponse(
status_code=500,
content={"detail": str(exc)}
)- Backend Setup:
cd backend
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
pip install -r requirements.txt- Frontend Setup:
cd frontend
npm install
npm run devCreate a .env file in the backend directory:
DATABASE_URL=sqlite:///./file_management.db
VECTOR_STORE_PATH=./vector_store
The API documentation is available at /docs when running the backend server. Key endpoints include:
POST /api/files/upload- Upload new filesGET /api/files- List all filesPOST /api/chat- Send chat messagesGET /api/vector-store/search- Search through document content
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request