yifan0sun commited on
Commit
2249c0c
·
verified ·
1 Parent(s): 618b4cb

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +19 -55
server.py CHANGED
@@ -14,7 +14,9 @@ from DISTILLBERTmodel import *
14
  import os
15
  import zipfile
16
  import shutil
17
-
 
 
18
 
19
  VISUALIZER_CLASSES = {
20
  "BERT": BERTVisualizer,
@@ -65,67 +67,29 @@ def ping():
65
 
66
 
67
 
 
 
 
 
 
 
 
68
 
69
- @app.post("/upload")
70
- async def upload(file: UploadFile = File(...)):
71
- path = f"/data/{file.filename}"
72
- with open(path, "wb") as f:
73
  f.write(await file.read())
74
- return {"status": "uploaded", "path": path}
75
-
76
-
77
- @app.post("/migrate_cache")
78
- def migrate_hf_cache():
79
- src_root = Path("/hf_cache")
80
- dst_root = Path("/data/hf_cache")
81
-
82
- if not src_root.exists():
83
- return {"status": "error", "message": "Source directory does not exist"}
84
-
85
- migrated_files = []
86
-
87
- for src_path in src_root.rglob("*"):
88
- if src_path.is_file():
89
- relative_path = src_path.relative_to(src_root)
90
- dst_path = dst_root / relative_path
91
 
92
- # Create destination directory if needed
93
- dst_path.parent.mkdir(parents=True, exist_ok=True)
94
-
95
- # Copy file
96
- shutil.copy2(src_path, dst_path)
97
- migrated_files.append(str(relative_path))
98
-
99
- return {
100
- "status": "done",
101
- "files_migrated": migrated_files,
102
- "total": len(migrated_files)
103
- }
104
 
105
 
106
 
107
 
108
- @app.get("/copy_and_extract")
109
- def copy_and_extract():
110
-
111
- printstr = copy_extract_and_report()
112
-
113
- return {"message": "done", "log": printstr}
114
-
115
-
116
-
117
-
118
-
119
- @app.get("/data_check")
120
- def data_check():
121
- with open("/data/marker.txt", "w") as f:
122
- f.write("hello from server.py\n")
123
-
124
- files = os.listdir("/data")
125
- return {
126
- "message": "done",
127
- "contents": files
128
- }
129
 
130
 
131
 
 
14
  import os
15
  import zipfile
16
  import shutil
17
+ from fastapi import Form
18
+ from fastapi import UploadFile, File, Form
19
+ from pathlib import Path
20
 
21
  VISUALIZER_CLASSES = {
22
  "BERT": BERTVisualizer,
 
67
 
68
 
69
 
70
+ @app.post("/upload_to_path")
71
+ async def upload_to_path(
72
+ file: UploadFile = File(...),
73
+ dest_path: str = Form(...) # e.g., "models/model.pt"
74
+ ):
75
+ full_path = Path("/data") / dest_path
76
+ full_path.parent.mkdir(parents=True, exist_ok=True)
77
 
78
+ with open(full_path, "wb") as f:
 
 
 
79
  f.write(await file.read())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
+ return {"status": "uploaded", "path": str(full_path)}
 
 
 
 
 
 
 
 
 
 
 
82
 
83
 
84
 
85
 
86
+ @app.post("/make_dir")
87
+ def make_directory(
88
+ dir_path: str = Form(...) # e.g., "logs/test_run"
89
+ ):
90
+ full_dir = Path("/data") / dir_path
91
+ full_dir.mkdir(parents=True, exist_ok=True)
92
+ return {"status": "created", "directory": str(full_dir)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
 
95