Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -14,17 +14,6 @@ import pandas as pd
|
|
| 14 |
from docx import Document
|
| 15 |
from pptx import Presentation
|
| 16 |
|
| 17 |
-
# Configuration du logging
|
| 18 |
-
logging.basicConfig(
|
| 19 |
-
level=logging.INFO,
|
| 20 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 21 |
-
handlers=[
|
| 22 |
-
logging.FileHandler("app.log"),
|
| 23 |
-
logging.StreamHandler()
|
| 24 |
-
]
|
| 25 |
-
)
|
| 26 |
-
logger = logging.getLogger(__name__)
|
| 27 |
-
|
| 28 |
# Initialisation de l'application FastAPI
|
| 29 |
app = FastAPI()
|
| 30 |
|
|
@@ -40,7 +29,22 @@ app.add_middleware(
|
|
| 40 |
# Chemins des fichiers
|
| 41 |
BASE_DIR = Path(__file__).parent
|
| 42 |
UPLOAD_FOLDER = BASE_DIR / "uploads"
|
|
|
|
|
|
|
|
|
|
| 43 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Configuration des modèles Hugging Face
|
| 46 |
HF_TOKEN = os.getenv("HF_TOKEN", "votre_token_ici")
|
|
@@ -92,12 +96,12 @@ async def read_root():
|
|
| 92 |
async def get_logs():
|
| 93 |
"""Endpoint pour récupérer les logs"""
|
| 94 |
try:
|
| 95 |
-
with open("app.log", "r") as f:
|
| 96 |
return {"logs": f.read()}
|
| 97 |
except FileNotFoundError:
|
| 98 |
raise HTTPException(404, "Aucun log disponible")
|
| 99 |
|
| 100 |
-
# Fonctions utilitaires
|
| 101 |
def extract_text_from_pdf(file_path: str) -> str:
|
| 102 |
try:
|
| 103 |
doc = fitz.open(file_path)
|
|
@@ -265,6 +269,5 @@ if __name__ == "__main__":
|
|
| 265 |
host="0.0.0.0",
|
| 266 |
port=8000,
|
| 267 |
reload=True,
|
| 268 |
-
workers=4
|
| 269 |
-
log_config="log.ini"
|
| 270 |
)
|
|
|
|
| 14 |
from docx import Document
|
| 15 |
from pptx import Presentation
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Initialisation de l'application FastAPI
|
| 18 |
app = FastAPI()
|
| 19 |
|
|
|
|
| 29 |
# Chemins des fichiers
|
| 30 |
BASE_DIR = Path(__file__).parent
|
| 31 |
UPLOAD_FOLDER = BASE_DIR / "uploads"
|
| 32 |
+
LOGS_DIR = BASE_DIR / "logs"
|
| 33 |
+
|
| 34 |
+
# Création des répertoires nécessaires avec les permissions appropriées
|
| 35 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 36 |
+
os.makedirs(LOGS_DIR, exist_ok=True)
|
| 37 |
+
|
| 38 |
+
# Configuration du logging avec le nouveau répertoire de logs
|
| 39 |
+
logging.basicConfig(
|
| 40 |
+
level=logging.INFO,
|
| 41 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 42 |
+
handlers=[
|
| 43 |
+
logging.FileHandler(LOGS_DIR / "app.log"),
|
| 44 |
+
logging.StreamHandler()
|
| 45 |
+
]
|
| 46 |
+
)
|
| 47 |
+
logger = logging.getLogger(__name__)
|
| 48 |
|
| 49 |
# Configuration des modèles Hugging Face
|
| 50 |
HF_TOKEN = os.getenv("HF_TOKEN", "votre_token_ici")
|
|
|
|
| 96 |
async def get_logs():
|
| 97 |
"""Endpoint pour récupérer les logs"""
|
| 98 |
try:
|
| 99 |
+
with open(LOGS_DIR / "app.log", "r") as f:
|
| 100 |
return {"logs": f.read()}
|
| 101 |
except FileNotFoundError:
|
| 102 |
raise HTTPException(404, "Aucun log disponible")
|
| 103 |
|
| 104 |
+
# Fonctions utilitaires
|
| 105 |
def extract_text_from_pdf(file_path: str) -> str:
|
| 106 |
try:
|
| 107 |
doc = fitz.open(file_path)
|
|
|
|
| 269 |
host="0.0.0.0",
|
| 270 |
port=8000,
|
| 271 |
reload=True,
|
| 272 |
+
workers=4
|
|
|
|
| 273 |
)
|