File size: 708 Bytes
7a76a88 da7e57f 62eb515 da7e57f 62eb515 da7e57f 62eb515 da7e57f 97d98e2 28cb163 62eb515 5cb25fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from fastapi import FastAPI
from transformers import pipeline
# Creating a new FastAPI app instance
app = FastAPI()
# Calling the Hugging Face Model from the pipeline
# Here I am using the Facebook/bart-large-cnn model for summarization
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Creating routes
@app.get("/")
def home():
return {"message": "Your FastAPI and Model is Running"}
@app.get("/chat")
def chat(text: str):
# Use the summarizer pipeline to generate a summary from the given input text
output = summarizer(text, max_length=130, min_length=30, do_sample=False)
# Return the summary from the output
return {"summary": output[0]['summary_text']}
|