yashxx07 commited on
Commit
c5b17a5
·
verified ·
1 Parent(s): 4526ad3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -14
main.py CHANGED
@@ -5,14 +5,14 @@ from fastapi.responses import StreamingResponse
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,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=False)
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
- # @app.post("/summarize-v1")
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
 
 
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