yashxx07 commited on
Commit
43e8e4e
·
verified ·
1 Parent(s): c5b17a5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +41 -41
main.py CHANGED
@@ -5,26 +5,20 @@ 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
 
19
- @app.get("/")
20
- async def root():
21
- return {"status": "OK"}
22
-
23
- class Item(BaseModel):
24
- url: str
25
- percentage: int
26
-
27
-
28
 
29
  def extract_article_content(url):
30
  try:
@@ -40,6 +34,12 @@ def extract_article_content(url):
40
  except Exception as e:
41
  return ""
42
 
 
 
 
 
 
 
43
  @app.post("/summarize-v1")
44
  async def root(item: Item):
45
 
@@ -71,29 +71,29 @@ async def root(item: Item):
71
 
72
 
73
 
74
- @app.post("/summarize-v2")
75
- async def root(item: Item):
76
- try:
77
- article = extract_article_content(item.url)
78
 
79
- if len(article) == 0:
80
- return StreamingResponse(content="", media_type="application/json")
81
 
82
- response = requests.post('https://fumes-api.onrender.com/llama3',
83
- json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
84
- "temperature":0.6,
85
- "topP":0.9,
86
- "maxTokens": 200}, stream=True)
87
 
88
- async def send_chunks():
89
- for chunk in response.iter_content(chunk_size=1024):
90
- if chunk:
91
- yield chunk.decode('utf-8')
92
 
93
- return StreamingResponse(send_chunks(), media_type="text/plain")
94
 
95
- except requests.RequestException as e:
96
- return {"error": str(e), "status_code": 500}
97
 
98
 
99
 
@@ -113,22 +113,22 @@ async def root(item: Item):
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
 
 
5
  from pydantic import BaseModel
6
  import re
7
  import os
8
+ # import transformers
9
+ # import torch
10
 
11
+ class Item(BaseModel):
12
+ url: str
13
+ percentage: int
14
 
15
+ app = FastAPI()
16
 
17
 
 
18
 
19
+ #summarizer = transformers.pipeline("summarization", model="Falconsai/text_summarization")
20
 
21
 
 
 
 
 
 
 
 
 
 
22
 
23
  def extract_article_content(url):
24
  try:
 
34
  except Exception as e:
35
  return ""
36
 
37
+
38
+ @app.get("/")
39
+ async def root():
40
+ return {"status": "OK"}
41
+
42
+
43
  @app.post("/summarize-v1")
44
  async def root(item: Item):
45
 
 
71
 
72
 
73
 
74
+ # @app.post("/summarize-v2")
75
+ # async def root(item: Item):
76
+ # try:
77
+ # article = extract_article_content(item.url)
78
 
79
+ # if len(article) == 0:
80
+ # return StreamingResponse(content="", media_type="application/json")
81
 
82
+ # response = requests.post('https://fumes-api.onrender.com/llama3',
83
+ # json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
84
+ # "temperature":0.6,
85
+ # "topP":0.9,
86
+ # "maxTokens": 200}, stream=True)
87
 
88
+ # async def send_chunks():
89
+ # for chunk in response.iter_content(chunk_size=1024):
90
+ # if chunk:
91
+ # yield chunk.decode('utf-8')
92
 
93
+ # return StreamingResponse(send_chunks(), media_type="text/plain")
94
 
95
+ # except requests.RequestException as e:
96
+ # return {"error": str(e), "status_code": 500}
97
 
98
 
99
 
 
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