lewiskimaru commited on
Commit
a3c1cdf
1 Parent(s): 91aac40

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +6 -8
modules/app.py CHANGED
@@ -1,6 +1,6 @@
1
  '''
2
  Created By Lewis Kamau Kimaru
3
- Sema translator api backend
4
  January 2024
5
  Docker deployment
6
  '''
@@ -8,8 +8,6 @@
8
  from fastapi import FastAPI, HTTPException, Request
9
  from fastapi.middleware.cors import CORSMiddleware
10
  from fastapi.responses import HTMLResponse
11
- from fastapi.staticfiles import StaticFiles
12
- from fastapi.responses import FileResponse, StreamingResponse
13
  import uvicorn
14
 
15
  import ctranslate2
@@ -35,7 +33,7 @@ app.add_middleware(
35
  fasttext.FastText.eprint = lambda x: None
36
 
37
  # User interface
38
- app.mount("/static", StaticFiles(directory="static"), name="static")
39
 
40
 
41
  # Get time of request
@@ -129,10 +127,10 @@ def translate_enter(userinput: str, source_lang: str, target_lang: str):
129
  return translations_desubword[0]
130
 
131
 
132
- @app.head("/")
133
- @app.get("/")
134
- def index() -> FileResponse:
135
- return FileResponse(path="static/index.html", media_type="text/html")
136
 
137
  @app.post("/translate_detect/")
138
  async def translate_detect_endpoint(request: Request):
 
1
  '''
2
  Created By Lewis Kamau Kimaru
3
+ Sema translator fastapi implementation
4
  January 2024
5
  Docker deployment
6
  '''
 
8
  from fastapi import FastAPI, HTTPException, Request
9
  from fastapi.middleware.cors import CORSMiddleware
10
  from fastapi.responses import HTMLResponse
 
 
11
  import uvicorn
12
 
13
  import ctranslate2
 
33
  fasttext.FastText.eprint = lambda x: None
34
 
35
  # User interface
36
+ templates_folder = os.path.join(os.path.dirname(__file__), "templates")
37
 
38
 
39
  # Get time of request
 
127
  return translations_desubword[0]
128
 
129
 
130
+ @app.get("/", response_class=HTMLResponse)
131
+ async def read_root(request: Request):
132
+ return HTMLResponse(content=open(os.path.join(templates_folder, "translator.html"), "r").read(), status_code=200)
133
+
134
 
135
  @app.post("/translate_detect/")
136
  async def translate_detect_endpoint(request: Request):