gmerrill commited on
Commit
9dab54d
·
1 Parent(s): 0bc8a9d
Files changed (3) hide show
  1. main.py +8 -2
  2. requirements.txt +1 -0
  3. static/script.js +9 -6
main.py CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
  from fastapi.staticfiles import StaticFiles
3
  from fastapi.responses import FileResponse
@@ -7,8 +13,8 @@ from transformers import pipeline
7
  app = FastAPI()
8
 
9
  @app.post("/query_gorilla")
10
- def query_gorilla(input):
11
- return input
12
 
13
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
14
 
 
1
+ from pydantic import BaseModel
2
+
3
+ class Request(BaseModel):
4
+ body: str
5
+
6
+
7
  from fastapi import FastAPI
8
  from fastapi.staticfiles import StaticFiles
9
  from fastapi.responses import FileResponse
 
13
  app = FastAPI()
14
 
15
  @app.post("/query_gorilla")
16
+ def query_gorilla(req: Request):
17
+ return str(req)
18
 
19
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
20
 
requirements.txt CHANGED
@@ -6,3 +6,4 @@ transformers==4.*
6
  uvicorn[standard]==0.17.*
7
  protobuf==4.*
8
  accelerate==0.27.*
 
 
6
  uvicorn[standard]==0.17.*
7
  protobuf==4.*
8
  accelerate==0.27.*
9
+ pydantic
static/script.js CHANGED
@@ -2,12 +2,15 @@ const textGenForm = document.querySelector('.text-gen-form');
2
 
3
  const translateText = async (text) => {
4
  const inferResponse = await fetch(
5
- `query_gorilla`,
6
- {
7
- method: 'POST',
8
- body: text
9
- }
10
- );
 
 
 
11
  const inferJson = await inferResponse.json();
12
 
13
  return inferJson.output;
 
2
 
3
  const translateText = async (text) => {
4
  const inferResponse = await fetch(
5
+ `query_gorilla`,
6
+ {
7
+ method: 'POST',
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ },
11
+ body: text
12
+ }
13
+ );
14
  const inferJson = await inferResponse.json();
15
 
16
  return inferJson.output;