Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from pydantic import BaseModel
|
|
| 3 |
from typing import List
|
| 4 |
from pathlib import Path
|
| 5 |
import shutil
|
|
|
|
| 6 |
|
| 7 |
from langchain_docling import DoclingLoader
|
| 8 |
from langchain_docling.loader import ExportType
|
|
@@ -18,10 +19,17 @@ UPLOAD_DIR.mkdir(exist_ok=True)
|
|
| 18 |
|
| 19 |
@app.post("/upload")
|
| 20 |
async def upload_file(file: UploadFile = File(...)):
|
| 21 |
-
print(file)
|
| 22 |
-
file_path = Path(file.filename)
|
| 23 |
-
with file_path.open("wb") as buffer:
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# result = process_with_langchain(file_path)
|
| 27 |
|
|
|
|
| 3 |
from typing import List
|
| 4 |
from pathlib import Path
|
| 5 |
import shutil
|
| 6 |
+
import tempfile
|
| 7 |
|
| 8 |
from langchain_docling import DoclingLoader
|
| 9 |
from langchain_docling.loader import ExportType
|
|
|
|
| 19 |
|
| 20 |
@app.post("/upload")
|
| 21 |
async def upload_file(file: UploadFile = File(...)):
|
| 22 |
+
# print(file)
|
| 23 |
+
# file_path = Path(file.filename)
|
| 24 |
+
# with file_path.open("wb") as buffer:
|
| 25 |
+
# shutil.copyfileobj(file.file, buffer)
|
| 26 |
+
|
| 27 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=file.filename) as temp_file:
|
| 28 |
+
# Efficiently write the uploaded file's content to the temporary file
|
| 29 |
+
contents = await file.read()
|
| 30 |
+
temp_file.write(contents)
|
| 31 |
+
|
| 32 |
+
temp_file_path = temp_file.name
|
| 33 |
|
| 34 |
# result = process_with_langchain(file_path)
|
| 35 |
|