Sergidev commited on
Commit
671e2ed
1 Parent(s): 220361b

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +17 -5
modules/app.py CHANGED
@@ -1,13 +1,18 @@
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import HTMLResponse, StreamingResponse
3
  from fastapi.staticfiles import StaticFiles
 
4
  from modules.pmbl import PMBL
5
- .html
 
 
 
 
 
6
 
7
- app = FastAPI()
8
  pmbl = PMBL("./PMB-7b.Q6_K.gguf") # Replace with the path to your model
9
 
10
- app.mount("/", StaticFiles(directory="static"), name="static")
11
 
12
  @app.post("/chat")
13
  async def chat(request: Request):
@@ -24,7 +29,7 @@ async def chat(request: Request):
24
 
25
  @app.get("/", response_class=HTMLResponse)
26
  async def root(request: Request):
27
- return static.TemplateResponse("index.html", {"request": request})
28
 
29
  @app.post("/sleep")
30
  async def sleep():
@@ -33,4 +38,11 @@ async def sleep():
33
  return {"message": "Sleep mode completed successfully"}
34
  except Exception as e:
35
  print(f"[SYSTEM] Error: {str(e)}")
36
- return {"error": str(e)}
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import HTMLResponse, StreamingResponse
3
  from fastapi.staticfiles import StaticFiles
4
+ from fastapi.templating import Jinja2Templates
5
  from modules.pmbl import PMBL
6
+ import os
7
+
8
+ app = FastAPI(docs_url=None, redoc_url=None)
9
+
10
+ # Mount static files
11
+ app.mount("/static", StaticFiles(directory="static"), name="static")
12
 
 
13
  pmbl = PMBL("./PMB-7b.Q6_K.gguf") # Replace with the path to your model
14
 
15
+ templates = Jinja2Templates(directory="static") # Update the directory to "static"
16
 
17
  @app.post("/chat")
18
  async def chat(request: Request):
 
29
 
30
  @app.get("/", response_class=HTMLResponse)
31
  async def root(request: Request):
32
+ return templates.TemplateResponse("index.html", {"request": request})
33
 
34
  @app.post("/sleep")
35
  async def sleep():
 
38
  return {"message": "Sleep mode completed successfully"}
39
  except Exception as e:
40
  print(f"[SYSTEM] Error: {str(e)}")
41
+ return {"error": str(e)}
42
+
43
+ if __name__ == "__main__":
44
+ import uvicorn
45
+ import asyncio
46
+
47
+ loop = asyncio.get_event_loop()
48
+ loop.run_until_complete(uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8000))))