rajeshradhakrishnan commited on
Commit
aeb02ac
1 Parent(s): 634c7fe

English-Malayalam Translate v27

Browse files
Files changed (4) hide show
  1. main.py +12 -5
  2. requirements.txt +1 -0
  3. static/index.html +3 -0
  4. static/script.js +1 -3
main.py CHANGED
@@ -1,7 +1,8 @@
1
  import os
2
- from fastapi import FastAPI
3
  from fastapi.staticfiles import StaticFiles
4
- from fastapi.responses import FileResponse
 
5
  from transformers import pipeline
6
 
7
 
@@ -17,6 +18,12 @@ def t5(input):
17
 
18
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
19
 
20
- @app.get("/")
21
- def index() -> FileResponse:
22
- return FileResponse(path="/app/static/index.html", media_type="text/html")
 
 
 
 
 
 
 
1
  import os
2
+ from fastapi import FastAPI, Request
3
  from fastapi.staticfiles import StaticFiles
4
+ from fastapi.responses import HTMLResponse
5
+ from fastapi.templating import Jinja2Templates
6
  from transformers import pipeline
7
 
8
 
 
18
 
19
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
20
 
21
+ # @app.get("/")
22
+ # def index() -> FileResponse:
23
+ # return FileResponse(path="/app/static/index.html", media_type="text/html")
24
+ templates = Jinja2Templates(directory="static")
25
+
26
+ @app.get("/", response_class=HTMLResponse)
27
+ async def index(request: Request):
28
+ apikey = {"APIKEY": os.environ.get("API_KEY")}
29
+ return templates.TemplateResponse("index.html", {"request": request,"apikey": apikey})
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  fastapi==0.74.*
 
2
  requests==2.27.*
3
  sentencepiece==0.1.*
4
  torch==1.11.*
 
1
  fastapi==0.74.*
2
+ jinja2
3
  requests==2.27.*
4
  sentencepiece==0.1.*
5
  torch==1.11.*
static/index.html CHANGED
@@ -26,6 +26,9 @@
26
  supervised-fine-tuning (SFT) model of the Open-Assistant project.
27
  </p>
28
  </section>
 
 
 
29
  <script src="script.js"></script>
30
  </body>
31
  </html>
 
26
  supervised-fine-tuning (SFT) model of the Open-Assistant project.
27
  </p>
28
  </section>
29
+ <script>
30
+ var apiKey = "{{ apikey.APIKEY }}";
31
+ </script>
32
  <script src="script.js"></script>
33
  </body>
34
  </html>
static/script.js CHANGED
@@ -1,6 +1,4 @@
1
-
2
- const API_KEY = process.env.API_KEY;
3
- console.log("API_KEY " + API_KEY)
4
  const translateText = async (text) => {
5
  const inferResponse = await fetch(`infer_t5?input=${text}`);
6
  const inferJson = await inferResponse.json();
 
1
+ console.log("API_KEY " + apiKey)
 
 
2
  const translateText = async (text) => {
3
  const inferResponse = await fetch(`infer_t5?input=${text}`);
4
  const inferJson = await inferResponse.json();