Tony Shepherd commited on
Commit
9033156
1 Parent(s): 31a2602

first attempt at transformer pipeline llm endpoint

Browse files
Files changed (3) hide show
  1. main.py +12 -3
  2. payload.py +3 -1
  3. requirements.txt +2 -3
main.py CHANGED
@@ -1,7 +1,16 @@
 
1
  from fastapi import FastAPI
 
2
 
3
  app = FastAPI()
4
 
5
- @app.get("/")
6
- def read_root():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
  from fastapi import FastAPI
3
+ from payload import SomeText
4
 
5
  app = FastAPI()
6
 
7
+ pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
8
+
9
+ @app.get("/api/check-heartbeat")
10
+ def get_heartbeat():
11
+ return {"Status": "Running. Try out the endpoints in swagger"}
12
+
13
+ @app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=SomeText)
14
+ def inference(input_prompt: SomeText):
15
+ output = pipe_flan(input_prompt)
16
+ return {"output": output[0]["generated_text"]}
payload.py CHANGED
@@ -12,4 +12,6 @@ class SomeText(BaseModel):
12
  }
13
  ]
14
  }
15
- }
 
 
 
12
  }
13
  ]
14
  }
15
+ }
16
+
17
+
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
- fastapi==0.74.*
2
- requests==2.27.*
3
- sentencepiece==0.1.*
4
  torch==1.11.*
5
  transformers==4.*
6
  uvicorn[standard]==0.17.*
 
 
 
 
 
 
1
  torch==1.11.*
2
  transformers==4.*
3
  uvicorn[standard]==0.17.*
4
+ fastapi==0.99.1
5
+ pydantic==1.10.12