Spaces:
Running
Running
lewiskimaru
commited on
Update modules/app.py
Browse files- modules/app.py +8 -17
modules/app.py
CHANGED
@@ -8,7 +8,6 @@
|
|
8 |
from fastapi import FastAPI, HTTPException, Request
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
from fastapi.responses import HTMLResponse
|
11 |
-
import gradio as gr
|
12 |
import ctranslate2
|
13 |
import sentencepiece as spm
|
14 |
import fasttext
|
@@ -31,6 +30,10 @@ app.add_middleware(
|
|
31 |
|
32 |
fasttext.FastText.eprint = lambda x: None
|
33 |
|
|
|
|
|
|
|
|
|
34 |
# Get time of request
|
35 |
|
36 |
def get_time():
|
@@ -121,22 +124,10 @@ def translate_enter(userinput: str, source_lang: str, target_lang: str):
|
|
121 |
# Return the source language and the translated text
|
122 |
return translations_desubword[0]
|
123 |
|
124 |
-
|
125 |
-
@app.get("/")
|
126 |
-
async def read_root():
|
127 |
-
|
128 |
-
<html>
|
129 |
-
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
|
130 |
-
<head>
|
131 |
-
<title>Sema</title>
|
132 |
-
</head>
|
133 |
-
<frameset>
|
134 |
-
<frame src=https://kamau1-semaapi-frontend.hf.space/?embedded=true'>
|
135 |
-
</frameset>
|
136 |
-
</html>
|
137 |
-
"""
|
138 |
-
return HTMLResponse(content=gradio_interface)
|
139 |
-
|
140 |
|
141 |
@app.post("/translate_detect/")
|
142 |
async def translate_detect_endpoint(request: Request):
|
|
|
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
|
|
|
30 |
|
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
|
38 |
|
39 |
def get_time():
|
|
|
124 |
# Return the source language and the translated text
|
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, "index.html"), "r").read(), status_code=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
@app.post("/translate_detect/")
|
133 |
async def translate_detect_endpoint(request: Request):
|