esteele commited on
Commit
60a515a
·
1 Parent(s): 4ab06eb

Edit utils.ts to use hf for uploads

Browse files
Files changed (1) hide show
  1. app/utils/file_utils.py +20 -2
app/utils/file_utils.py CHANGED
@@ -3,12 +3,30 @@ import shutil
3
 
4
  from fastapi import UploadFile
5
 
6
- UPLOAD_DIR = "uploads"
 
 
 
 
 
 
 
 
 
 
 
 
7
  os.makedirs(UPLOAD_DIR, exist_ok=True)
8
 
9
  def save_upload_file(file: UploadFile) -> str:
 
 
 
 
10
  file_path = os.path.join(UPLOAD_DIR, file.filename)
 
 
11
  with open(file_path, "wb") as buffer:
12
  shutil.copyfileobj(file.file, buffer)
13
- # print(f"File path: {file_path.split(',')[0]}{file_path.split(',')[-1]}")
14
  return file_path
 
3
 
4
  from fastapi import UploadFile
5
 
6
+ # UPLOAD_DIR = "uploads"
7
+ # os.makedirs(UPLOAD_DIR, exist_ok=True)
8
+
9
+ # def save_upload_file(file: UploadFile) -> str:
10
+ # file_path = os.path.join(UPLOAD_DIR, file.filename)
11
+ # with open(file_path, "wb") as buffer:
12
+ # shutil.copyfileobj(file.file, buffer)
13
+ # # print(f"File path: {file_path.split(',')[0]}{file_path.split(',')[-1]}")
14
+ # return file_path
15
+
16
+
17
+ # Use ./data/uploads for writable folder inside Hugging Face Spaces
18
+ UPLOAD_DIR = "./data/uploads"
19
  os.makedirs(UPLOAD_DIR, exist_ok=True)
20
 
21
  def save_upload_file(file: UploadFile) -> str:
22
+ """
23
+ Save an uploaded file to the UPLOAD_DIR
24
+ Returns the full file path
25
+ """
26
  file_path = os.path.join(UPLOAD_DIR, file.filename)
27
+
28
+ # Save file
29
  with open(file_path, "wb") as buffer:
30
  shutil.copyfileobj(file.file, buffer)
31
+
32
  return file_path