backend: make the data directory and the artifacts from the frontend customizable using environment variables

Signed-off-by: lucasew <lucas59356@gmail.com>
This commit is contained in:
lucasew 2024-01-19 17:13:09 -03:00
parent e3503d6617
commit 5b26d2a686
4 changed files with 16 additions and 14 deletions

View file

@ -11,7 +11,7 @@ import json
from utils.misc import calculate_sha256
from config import OLLAMA_API_BASE_URL
from config import OLLAMA_API_BASE_URL, DATA_DIR, UPLOAD_DIR
from constants import ERROR_MESSAGES
@ -96,8 +96,7 @@ async def download(
file_name = parse_huggingface_url(url)
if file_name:
os.makedirs("./uploads", exist_ok=True)
file_path = os.path.join("./uploads", f"{file_name}")
file_path = str(UPLOAD_DIR / file_name)
return StreamingResponse(
download_file_stream(url, file_path, file_name),
@ -109,16 +108,15 @@ async def download(
@router.post("/upload")
def upload(file: UploadFile = File(...)):
os.makedirs("./data/uploads", exist_ok=True)
file_path = os.path.join("./data/uploads", file.filename)
file_path = UPLOAD_DIR / file.filename
# Save file in chunks
with open(file_path, "wb+") as f:
with file_path.open("wb+") as f:
for chunk in file.file:
f.write(chunk)
def file_process_stream():
total_size = os.path.getsize(file_path)
total_size = os.path.getsize(str(file_path))
chunk_size = 1024 * 1024
try:
with open(file_path, "rb") as f: