Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
@app.get("/")
|
| 7 |
-
def
|
| 8 |
-
return {"message":
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
-
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 12 |
|
| 13 |
@app.get("/generate")
|
| 14 |
-
def generate(
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
return
|
|
|
|
| 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 |
|