Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -5,14 +5,14 @@ from fastapi.responses import StreamingResponse
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
|
| 18 |
|
|
@@ -54,7 +54,7 @@ async def root(item: Item):
|
|
| 54 |
json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
|
| 55 |
"temperature":0.6,
|
| 56 |
"topP":0.9,
|
| 57 |
-
"maxTokens": 200}, stream=
|
| 58 |
|
| 59 |
response_content = response.content.decode('utf-8')
|
| 60 |
|
|
@@ -113,22 +113,22 @@ async def root(item: Item):
|
|
| 113 |
return {"error": str(e), "status_code": 500}
|
| 114 |
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
|
| 134 |
|
|
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
+
import transformers
|
| 9 |
+
import torch
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
+
summarizer = transformers.pipeline("summarization", model="Falconsai/text_summarization")
|
| 16 |
|
| 17 |
|
| 18 |
|
|
|
|
| 54 |
json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
|
| 55 |
"temperature":0.6,
|
| 56 |
"topP":0.9,
|
| 57 |
+
"maxTokens": 200}, stream=True)
|
| 58 |
|
| 59 |
response_content = response.content.decode('utf-8')
|
| 60 |
|
|
|
|
| 113 |
return {"error": str(e), "status_code": 500}
|
| 114 |
|
| 115 |
|
| 116 |
+
@app.post("/summarize-v3")
|
| 117 |
+
async def root(item: Item):
|
| 118 |
|
| 119 |
+
try:
|
| 120 |
|
| 121 |
+
article = extract_article_content(item.url)
|
| 122 |
|
| 123 |
+
if len(article) == 0:
|
| 124 |
+
return {'summary': ""}
|
| 125 |
|
| 126 |
+
summ = summarizer(article, max_length=1000, min_length=30, do_sample=False)
|
| 127 |
|
| 128 |
+
return {"summary":summ}
|
| 129 |
|
| 130 |
+
except requests.RequestException as e:
|
| 131 |
+
return {"error": str(e), "status_code": 500}
|
| 132 |
|
| 133 |
|
| 134 |
|