Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
-
import mimetypes
|
| 4 |
import os
|
|
|
|
| 5 |
from typing import Optional
|
| 6 |
|
| 7 |
from docx import Document
|
| 8 |
import pdfplumber
|
| 9 |
import pandas as pd
|
| 10 |
-
from tempfile import NamedTemporaryFile
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
def extract_text_from_docx(file_path):
|
| 15 |
doc = Document(file_path)
|
| 16 |
-
return "\n".join([
|
| 17 |
|
| 18 |
def extract_text_from_pdf(file_path):
|
| 19 |
text = ""
|
|
@@ -23,8 +22,7 @@ def extract_text_from_pdf(file_path):
|
|
| 23 |
return text
|
| 24 |
|
| 25 |
def extract_text_from_sheet(file_path):
|
| 26 |
-
|
| 27 |
-
if ext == ".csv":
|
| 28 |
df = pd.read_csv(file_path)
|
| 29 |
else:
|
| 30 |
df = pd.read_excel(file_path)
|
|
@@ -58,3 +56,8 @@ async def upload(file: UploadFile = File(...)):
|
|
| 58 |
"type": mime_type,
|
| 59 |
"texte": texte
|
| 60 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
from fastapi.responses import JSONResponse
|
|
|
|
| 3 |
import os
|
| 4 |
+
from tempfile import NamedTemporaryFile
|
| 5 |
from typing import Optional
|
| 6 |
|
| 7 |
from docx import Document
|
| 8 |
import pdfplumber
|
| 9 |
import pandas as pd
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
def extract_text_from_docx(file_path):
|
| 14 |
doc = Document(file_path)
|
| 15 |
+
return "\n".join([p.text for p in doc.paragraphs])
|
| 16 |
|
| 17 |
def extract_text_from_pdf(file_path):
|
| 18 |
text = ""
|
|
|
|
| 22 |
return text
|
| 23 |
|
| 24 |
def extract_text_from_sheet(file_path):
|
| 25 |
+
if file_path.endswith(".csv"):
|
|
|
|
| 26 |
df = pd.read_csv(file_path)
|
| 27 |
else:
|
| 28 |
df = pd.read_excel(file_path)
|
|
|
|
| 56 |
"type": mime_type,
|
| 57 |
"texte": texte
|
| 58 |
}
|
| 59 |
+
|
| 60 |
+
# ✅ Ajoute un point de test
|
| 61 |
+
@app.get("/")
|
| 62 |
+
def ping():
|
| 63 |
+
return {"message": "L'API fonctionne ✅"}
|