Spaces:
Runtime error
Runtime error
File size: 963 Bytes
8eed7e4 7de4082 73e6e91 8eed7e4 7de4082 73e6e91 93795ea 8eed7e4 7de4082 73e6e91 26648cc 73e6e91 26648cc 73e6e91 7de4082 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from typing import Union
from fastapi import FastAPI
from transformers import pipeline
from newspaper import Article
app = FastAPI()
# see dockerfile. it has a line to download the model when the docket container is initialized
# summarizer = pipeline("summarization", "/code/models")
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
@app.post("/summarize")
async def summarize(text: str):
# url = 'https://towardsdatascience.com/containerizing-huggingface-transformers-for-gpu-inference-with-docker-and-fastapi-on-aws-d4a83edede2f'
article = Article(text)
article.download()
article.parse()
return {"summary": f"{summarizer(article.text, max_length=130, min_length=30, do_sample=False)}"}
|