Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,4 +1,5 @@
1
- from fastapi import FastAPI
 
2
  from transformers import pipeline
3
  app = FastAPI()
4
 
@@ -15,18 +16,19 @@ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
15
  # model = AutoModelForSeq2SeqLM.from_pretrained("ofintech/FinGPT_0.1.3")
16
  # pipe = pipeline("text2text-generation", model="MudassirFayaz/llama-2-7b_career_0.6.0", tokenizer=tokenizer)
17
 
18
-
19
  @app.get("/")
20
  def home():
21
- return {"message":"Hello World"}
22
-
23
- # Define a function to handle the GET request at `/generate`
24
 
 
 
 
25
 
26
- @app.get("/generate")
27
- def generate(text:str):
28
- ## use the pipeline to generate text from given input text
29
- output=pipe(text)
 
30
 
31
- ## return the generate text in Json reposne
32
- return {"output":output[0]['generated_text']}
 
1
+ from fastapi import FastAPI,Query
2
+ from pydantic import BaseModel
3
  from transformers import pipeline
4
  app = FastAPI()
5
 
 
16
  # model = AutoModelForSeq2SeqLM.from_pretrained("ofintech/FinGPT_0.1.3")
17
  # pipe = pipeline("text2text-generation", model="MudassirFayaz/llama-2-7b_career_0.6.0", tokenizer=tokenizer)
18
 
 
19
  @app.get("/")
20
  def home():
21
+ return {"message": "Hello World"}
 
 
22
 
23
+ # Define a request model
24
+ class TextRequest(BaseModel):
25
+ text: str
26
 
27
+ # Define a function to handle the POST request at `/generate`
28
+ @app.post("/generate")
29
+ def generate(request: TextRequest):
30
+ # Use the pipeline to generate text from given input text
31
+ output = pipe(request.text)
32
 
33
+ # Return the generated text in JSON response
34
+ return {"output": output[0]['generated_text']}