Spaces:
Running
Running
bart summarizer
Browse files
main.py
CHANGED
|
@@ -4,7 +4,9 @@ from fastapi import FastAPI
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import os
|
|
|
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
app = FastAPI()
|
|
@@ -105,21 +107,7 @@ async def root(item: Item):
|
|
| 105 |
|
| 106 |
article = extract_article_content(item.url)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
if token:
|
| 110 |
-
print(token)
|
| 111 |
-
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
| 112 |
-
headers = {'Authorization': token}
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
params = {'do_sample': False}
|
| 116 |
-
|
| 117 |
-
response = requests.post(API_URL, headers=headers, json={
|
| 118 |
-
'inputs': article,
|
| 119 |
-
'parameters': params
|
| 120 |
-
})
|
| 121 |
-
|
| 122 |
-
output = response.json()
|
| 123 |
|
| 124 |
return {"summary": output}
|
| 125 |
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import os
|
| 7 |
+
from transformers import pipeline
|
| 8 |
|
| 9 |
+
bart_summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
|
| 11 |
|
| 12 |
app = FastAPI()
|
|
|
|
| 107 |
|
| 108 |
article = extract_article_content(item.url)
|
| 109 |
|
| 110 |
+
output = summarizer(ARTICLE, max_length=130, min_length=30, do_sample=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
return {"summary": output}
|
| 113 |
|