ch404 commited on
Commit
5dc7523
·
1 Parent(s): 1a0df10

restructureapp

Browse files
Dockerfile CHANGED
@@ -11,4 +11,4 @@ COPY --chown=user ./requirements.txt requirements.txt
11
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
12
 
13
  COPY --chown=user . /app
14
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
11
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
12
 
13
  COPY --chown=user . /app
14
+ CMD ["uvicorn", "app:main", "--host", "0.0.0.0", "--port", "7860"]
app.py → app/main.py RENAMED
@@ -32,10 +32,15 @@ tensor = torch.randn(3, 3).to(device)
32
  @asynccontextmanager
33
  async def lifespan(app: FastAPI):
34
  print("Starting the app")
35
- yield
36
- print("Stopping the app")
 
 
 
 
 
37
 
38
- app = FastAPI()
39
 
40
  tokenizer = AutoTokenizer.from_pretrained(model_name, token=huggingface_token)
41
  model = AutoModelForCausalLM.from_pretrained(model_name, token=huggingface_token)
@@ -88,7 +93,7 @@ async def websocket_endpoint(websocket: WebSocket):
88
  await websocket.accept()
89
  await websocket.send_text("Hello, this is the Heisterbot chat server. Please send a message /chat")
90
 
91
- @app.websocket("/chat", name="chat", summary="Chat with the Heisterbot", description="Chat with the Heisterbot")
92
  async def websocket_endpoint(websocket: WebSocket):
93
  print("Client connected at: ", websocket.client)
94
  await websocket.accept()
 
32
  @asynccontextmanager
33
  async def lifespan(app: FastAPI):
34
  print("Starting the app")
35
+ try:
36
+ yield
37
+ finally:
38
+ print("Stopping the app")
39
+ # Ensure proper cleanup
40
+ del tensor
41
+ torch.cuda.empty_cache()
42
 
43
+ app = FastAPI(lifespan=lifespan)
44
 
45
  tokenizer = AutoTokenizer.from_pretrained(model_name, token=huggingface_token)
46
  model = AutoModelForCausalLM.from_pretrained(model_name, token=huggingface_token)
 
93
  await websocket.accept()
94
  await websocket.send_text("Hello, this is the Heisterbot chat server. Please send a message /chat")
95
 
96
+ @app.websocket("/chat",)
97
  async def websocket_endpoint(websocket: WebSocket):
98
  print("Client connected at: ", websocket.client)
99
  await websocket.accept()
models.py → app/models.py RENAMED
File without changes