Empereur-Pirate commited on
Commit
1b710b0
·
verified ·
1 Parent(s): c412dbc

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -3
main.py CHANGED
@@ -1,8 +1,20 @@
1
  from fastapi import FastAPI
 
2
 
3
  app = FastAPI()
4
 
5
- @app.get("/")
6
 
7
- def read_root():
8
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from transformers import pipeline
3
 
4
  app = FastAPI()
5
 
6
+ pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
7
 
8
+ def t5(input):
9
+ output = pipe_flan(input)
10
+ return {"output": output[0]["generated_text"]}
11
+
12
+ @app.post("/infer_t5")
13
+ def infer_endpoint(data: dict):
14
+ """Receive input and generate text."""
15
+ input_text = data.get("input")
16
+ if input_text is None:
17
+ return {"error": "No input text detected."}
18
+ else:
19
+ result = t5(input_text)
20
+ return result