Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -6,7 +6,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
6 |
from queue import Empty
|
7 |
import os
|
8 |
app = FastAPI()
|
9 |
-
|
10 |
# @app.on_event("startup")
|
11 |
# async def startup():
|
12 |
# FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
|
@@ -37,8 +37,6 @@ from typing import Dict
|
|
37 |
from datetime import datetime, timedelta
|
38 |
import psutil
|
39 |
|
40 |
-
app = FastAPI()
|
41 |
-
|
42 |
# Model for input data
|
43 |
class CodeExecutionRequest(BaseModel):
|
44 |
session_token: str
|
@@ -70,6 +68,11 @@ async def kill_kernel(session_token: str):
|
|
70 |
async def execute_code(session_token: str, code: str):
|
71 |
setup_code = "%matplotlib inline"
|
72 |
|
|
|
|
|
|
|
|
|
|
|
73 |
if session_token not in kernel_managers:
|
74 |
await create_kernel(session_token)
|
75 |
|
@@ -77,6 +80,8 @@ async def execute_code(session_token: str, code: str):
|
|
77 |
kc = km.client()
|
78 |
|
79 |
try:
|
|
|
|
|
80 |
# Execute setup code
|
81 |
kc.execute_interactive(setup_code, store_history=False)
|
82 |
# Execute the provided code
|
|
|
6 |
from queue import Empty
|
7 |
import os
|
8 |
app = FastAPI()
|
9 |
+
root_dir = os.getcwd()
|
10 |
# @app.on_event("startup")
|
11 |
# async def startup():
|
12 |
# FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
|
|
|
37 |
from datetime import datetime, timedelta
|
38 |
import psutil
|
39 |
|
|
|
|
|
40 |
# Model for input data
|
41 |
class CodeExecutionRequest(BaseModel):
|
42 |
session_token: str
|
|
|
68 |
async def execute_code(session_token: str, code: str):
|
69 |
setup_code = "%matplotlib inline"
|
70 |
|
71 |
+
session_dir = os.path.join(root_dir,output, session_token)
|
72 |
+
|
73 |
+
if not os.path.exists(session_dir):
|
74 |
+
os.makedirs(session_dir)
|
75 |
+
|
76 |
if session_token not in kernel_managers:
|
77 |
await create_kernel(session_token)
|
78 |
|
|
|
80 |
kc = km.client()
|
81 |
|
82 |
try:
|
83 |
+
os.chdir(session_dir)
|
84 |
+
print("current working directory",os.getcwd())
|
85 |
# Execute setup code
|
86 |
kc.execute_interactive(setup_code, store_history=False)
|
87 |
# Execute the provided code
|