adi21singh commited on
Commit
bb6e156
·
verified ·
1 Parent(s): 1ee748d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ ##create a new FastApi app instance
5
+
6
+ app=FastAPI()
7
+
8
+ # Initialize the text generation pipeline
9
+
10
+ pipe=pipeline("text2text-generation", model="google/flan-t5-small")
11
+
12
+ @app.get('/')
13
+ def home():
14
+ return {"message":"Hello world"}
15
+
16
+ #define a function to handle the Get request '/generate'
17
+
18
+ @app.get("/generate")
19
+ def generate(text:str):
20
+ ## use the pipeline to generate text from the given input text
21
+ output=pipe(text)
22
+
23
+ ##return the generated text
24
+ return{"output":output[0]['generated_text']}