This commit is contained in:
Saifeddine ALOUI
2025-01-30 23:29:21 +01:00
parent 219cbab1e3
commit 381f7deec6
2 changed files with 13 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
from fastapi import FastAPI, HTTPException, File, UploadFile, Form, Request from fastapi import FastAPI, HTTPException, File, UploadFile, Form, Request
# Backend (Python) # Backend (Python)
# Add this to store progress globally # Add this to store progress globally
from typing import Dict from typing import Dict
@@ -10,7 +11,7 @@ scan_progress: Dict = {
"current_file": "", "current_file": "",
"indexed_count": 0, "indexed_count": 0,
"total_files": 0, "total_files": 0,
"progress": 0 "progress": 0,
} }
# Lock for thread-safe operations # Lock for thread-safe operations
@@ -23,7 +24,6 @@ from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel from pydantic import BaseModel
import logging import logging
import argparse import argparse
import json
import time import time
import re import re
from typing import List, Dict, Any, Optional, Union from typing import List, Dict, Any, Optional, Union
@@ -36,7 +36,6 @@ from pathlib import Path
import shutil import shutil
import aiofiles import aiofiles
from ascii_colors import trace_exception, ASCIIColors from ascii_colors import trace_exception, ASCIIColors
import os
import sys import sys
import configparser import configparser
@@ -1010,7 +1009,6 @@ def create_app(args):
else: else:
logging.warning(f"No content extracted from file: {file_path}") logging.warning(f"No content extracted from file: {file_path}")
@app.post("/documents/scan", dependencies=[Depends(optional_api_key)]) @app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
async def scan_for_new_documents(): async def scan_for_new_documents():
"""Trigger the scanning process""" """Trigger the scanning process"""
@@ -1037,7 +1035,10 @@ def create_app(args):
with progress_lock: with progress_lock:
scan_progress["indexed_count"] += 1 scan_progress["indexed_count"] += 1
scan_progress["progress"] = (scan_progress["indexed_count"] / scan_progress["total_files"]) * 100 scan_progress["progress"] = (
scan_progress["indexed_count"]
/ scan_progress["total_files"]
) * 100
except Exception as e: except Exception as e:
logging.error(f"Error indexing file {file_path}: {str(e)}") logging.error(f"Error indexing file {file_path}: {str(e)}")
@@ -1059,8 +1060,6 @@ def create_app(args):
with progress_lock: with progress_lock:
return scan_progress return scan_progress
@app.post("/documents/upload", dependencies=[Depends(optional_api_key)]) @app.post("/documents/upload", dependencies=[Depends(optional_api_key)])
async def upload_to_input_dir(file: UploadFile = File(...)): async def upload_to_input_dir(file: UploadFile = File(...)):
""" """