lewiskimaru commited on
Commit
b6a33ff
1 Parent(s): 1989bb0

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +11 -6
modules/app.py CHANGED
@@ -8,10 +8,14 @@
8
  from fastapi import FastAPI, HTTPException, Request
9
  from fastapi.middleware.cors import CORSMiddleware
10
  from fastapi.responses import HTMLResponse
 
 
 
 
11
  import ctranslate2
12
  import sentencepiece as spm
13
  import fasttext
14
- import uvicorn
15
  import pytz
16
  from datetime import datetime
17
  import os
@@ -31,7 +35,7 @@ app.add_middleware(
31
  fasttext.FastText.eprint = lambda x: None
32
 
33
  # User interface
34
- templates_folder = os.path.join(os.path.dirname(__file__), "templates")
35
 
36
 
37
  # Get time of request
@@ -125,10 +129,11 @@ def translate_enter(userinput: str, source_lang: str, target_lang: str):
125
  return translations_desubword[0]
126
 
127
 
128
- @app.get("/", response_class=HTMLResponse)
129
- async def read_root(request: Request):
130
- return HTMLResponse(content=open(os.path.join(templates_folder, "translator.html"), "r").read(), status_code=200)
131
-
 
132
  @app.post("/translate_detect/")
133
  async def translate_detect_endpoint(request: Request):
134
  datad = await request.json()
 
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
16
  import sentencepiece as spm
17
  import fasttext
18
+
19
  import pytz
20
  from datetime import datetime
21
  import os
 
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
  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):
139
  datad = await request.json()