Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,22 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
app=FastAPI()
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
@app.get("/")
|
| 13 |
def home():
|
| 14 |
return {"message": "Your FastAPI and Model is Running"}
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#return the correct key based on model output
|
| 23 |
-
return {"output": output[0]['generated_text']}
|
| 24 |
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Creating a new FastAPI app instance
|
| 5 |
+
app = FastAPI()
|
| 6 |
|
| 7 |
+
# Calling the Hugging Face Model from the pipeline
|
| 8 |
+
# Here I am using the Facebook/bart-large-cnn model for summarization
|
| 9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
|
| 11 |
+
# Creating routes
|
| 12 |
@app.get("/")
|
| 13 |
def home():
|
| 14 |
return {"message": "Your FastAPI and Model is Running"}
|
| 15 |
|
| 16 |
+
@app.get("/chat")
|
| 17 |
+
def chat(text: str):
|
| 18 |
+
# Use the summarizer pipeline to generate a summary from the given input text
|
| 19 |
+
output = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 20 |
+
# Return the summary from the output
|
| 21 |
+
return {"summary": output[0]['summary_text']}
|
|
|
|
|
|
|
| 22 |
|