vroy02243 commited on
Commit
b923f4c
·
verified ·
1 Parent(s): a62c7a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -1,18 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
  from transformers import pipeline
3
 
4
- app = FastAPI() # app instance
 
 
 
 
 
5
 
6
  @app.get("/")
7
- def root():
8
- return {"message": "Hello World"}
9
 
 
10
 
11
- pipe = pipeline("text2text-generation", model="google/flan-t5-small")
12
 
13
  @app.get("/generate")
14
- def generate(prompt: str):
15
- response = pipe(prompt)
 
16
 
17
- return {"response": response[0]['generated_text']}
 
18
 
 
1
+ # from fastapi import FastAPI
2
+ # from transformers import pipeline
3
+
4
+ # app = FastAPI() # app instance
5
+
6
+ # @app.get("/")
7
+ # def root():
8
+ # return {"message": "Hello World"}
9
+
10
+
11
+ # pipe = pipeline("text2text-generation", model="google/flan-t5-small")
12
+
13
+ # @app.get("/generate")
14
+ # def generate(prompt: str):
15
+ # response = pipe(prompt)
16
+
17
+ # return {"response": response[0]['generated_text']}
18
+
19
  from fastapi import FastAPI
20
  from transformers import pipeline
21
 
22
+ ## create a new FASTAPI app instance
23
+ app=FastAPI()
24
+
25
+ # Initialize the text generation pipeline
26
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
27
+
28
 
29
  @app.get("/")
30
+ def home():
31
+ return {"message":"Hello World"}
32
 
33
+ # Define a function to handle the GET request at `/generate`
34
 
 
35
 
36
  @app.get("/generate")
37
+ def generate(text:str):
38
+ ## use the pipeline to generate text from given input text
39
+ output=pipe(text)
40
 
41
+ ## return the generate text in Json reposne
42
+ return {"output":output[0]['generated_text']}
43