ksvmuralidhar commited on
Commit
0d3223b
1 Parent(s): bc12604

Upload news_summarizer_api_example.ipynb

Browse files
Files changed (1) hide show
  1. news_summarizer_api_example.ipynb +268 -0
news_summarizer_api_example.ipynb ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "f1976c16-cfc7-4d2d-8c7e-71d72dba78b6",
7
+ "metadata": {
8
+ "tags": []
9
+ },
10
+ "outputs": [],
11
+ "source": [
12
+ "import requests\n",
13
+ "import os\n",
14
+ "import json"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 3,
20
+ "id": "a90dde3c-c536-4828-95cc-dbe1bbedd39d",
21
+ "metadata": {
22
+ "tags": []
23
+ },
24
+ "outputs": [],
25
+ "source": [
26
+ "api_endpoint = os.getenv('API_ENDPOINT')\n",
27
+ "api_key = os.getenv('API_KEY')"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 4,
33
+ "id": "5e08f601-f431-4ba2-97c3-eee6ba769682",
34
+ "metadata": {
35
+ "tags": []
36
+ },
37
+ "outputs": [
38
+ {
39
+ "name": "stdout",
40
+ "output_type": "stream",
41
+ "text": [
42
+ "200\n"
43
+ ]
44
+ },
45
+ {
46
+ "data": {
47
+ "text/plain": [
48
+ "{'urls': ['https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445',\n",
49
+ " 'https://www.thehindu.com/news/national/tmc-dharna-derek-obrien-saket-gokhale-others-continue-dharna-at-delhis-mandir-marg-police-station/article68046304.ece',\n",
50
+ " 'https://www.livemint.com/news/india/arvind-kejriwal-will-move-supreme-court-sc-against-delhi-hcs-order-in-excise-policy-case-sources-11712660787632.html',\n",
51
+ " 'https://www.moneycontrol.com/news/technicals/technical-view-nifty39s-record-rally-continues-crosses-22750-for-first-time-resistance-at-22740-22770_17520591.html',\n",
52
+ " '1'],\n",
53
+ " 'scraped_texts': [\"The U.S. tech firm will announce the plans soon when Japanese Prime Minister Fumio Kishida visits the United States, the Nikkei said in its interview with Microsoft President Brad Smith.\\nMicrosoft Corp will invest about $2.9 billion over the next two years to boost its artificial intelligence (AI) business in Japan, the Nikkei newspaper reported on Tuesday citing the company president.\\nThe U.S. tech firm will announce the plans soon when Japanese Prime Minister Fumio Kishida visits the United States, the Nikkei said in its interview with Microsoft President Brad Smith.\\nUnder the plan, which the Nikkei said would be Microsoft's largest investment in Japan, the company will install advanced AI semiconductors at two existing facilities in eastern and western Japan, the report said. The company also plans to announce an AI-related reskilling program in Japan to train 3 million workers over three years, and to set up a new lab in Tokyo for research and development on robotics and AI, the report said.\\nCentral Bank Fixed Deposit: How much will you earn by investing Rs 1 lakh, 3 lakh and 5 lakh at 8.05% interest rate?\\nBy accepting cookies, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.\",\n",
54
+ " 'Trinamool Congress (TMC) leaders who were detained by Delhi Police while staging a dharna outside the Election Commission\\'s office continued their protest at Mandir Marg police station on April 9.\\nAAP leaders, including Saurabh Bharadwaj, met the protesting TMC leaders who camped overnight at the police station.\\nThe TMC leaders had met the full bench of the EC on Monday, demanding that the heads of the Enforcement Directorate, Central Bureau of Investigation, National Investigation Agency and Income Tax department be changed as they were allegedly acting at the behest of the ruling BJP.\\nThe TMC leaders later announced they were sitting on a 24-hour dharna outside the EC office. The delegation comprised Rajya Sabha MP Derek O\\'Brien, Mohammed Nadimul Haque, Dola Sen, Saket Gokhale, Sagarika Ghose, MLA Vivek Gupta, former MPs Arpita Ghosh, Santanu Sen and Abir Ranjan Biswas and TMC West Bengal students\\' wing vice-president Sudip Raha. The leaders were later detained by Delhi Police and forcefully evicted from the site.\\nPolice said they released the TMC leaders on Monday night. However, the leaders stayed put at the police station through the night and continued their dharna.\\nIn a post on X on Tuesday, Mr. Gokhale said the party leaders were continuing their protest at the police station.\\nWhile all TMC leaders sat inside the police station premises, Mr. Haque and Mr. Ghose, who had gone out briefly, were not allowed to re-enter. They sat on a dharna outside the boundary of the police station.\\nAsked about the police statement that the TMC leaders were released from detention on Monday evening, Haque said, \"We had announced a 24-hour dharna. They did not allow us to sit in front of the EC and brought us here. So, we are sitting here,\" he said.\\nThe Mamata Banerjee-led TMC has been alleging that the central probe agencies have been targeting opposition parties ahead of the Lok Sabha polls at the behest of the BJP-led central government.',\n",
55
+ " 'Delhi Chief Minister Arvind Kejriwal will move the Supreme Court against Delhi High Court\\'s order in excise policy case.\\nThe Aam Aadmi Party announced on Tuesday that Delhi Chief Minister Arvind Kejriwal \"will approach the Supreme Court against the Delhi High Court\\'s order\" rejecting his plea challenging his arrest and remand by the Enforcement Directorate in the excise policy case.\\nAam Aadmi Party leader Saurabh Bharadwaj stated that the party has full faith in the Supreme Court. “We believe it will grant relief to CM Kejriwal, as it did to Sanjay Singh,\" he added. \"We disagree with the Delhi High Court\\'s order,\" he said. AAP MP Sanjay Singh was arrested in connection with the same liquor case and was recently granted bail by the Supreme Court.\\nMeanwhile, sources in the AAP told news agency ANI that the party doe not agree with the Delhi High Court\\'s decision. “The Aam Aadmi Party does not agree with the decision of the Delhi High Court. Kejriwal will go to the Supreme Court against HC\\'s decision. Kejriwal can go to the Supreme Court tomorrow itself.\"\\nEarlier, the Delhi High Court dismissed CM Arvind Kejriwal\\'s plea, calling his arrest and remand by the Enforcement Directorate \"valid\". The bench of Justice Swarna Kanta Sharma said the ED was in possession of enough material, which led them to arrest Kejriwal.\\nReacting to the order, Delhi BJP president Virendraa Sachdeva said, \"...If leaders of the Aam Aadmi Party have some ethics left, then they should apologise to the people of Delhi...If they (AAP) are questioning the court\\'s decision now then it is an insult...\"\\nKejriwal was arrested by the the Enforcement Directorate on March 21 in relation to the excise policy case. Later, a trial court sent Arvind Kejriwal to judicial custody till April 15, 2024.\\nThe Enforcement Directorate alleged that the AAP is the major beneficiary of the proceeds of crime generated in the alleged liquor scam. The agency also claimed that Kejriwal was directly involved in the formation of the excise policy.\\nThe case pertains to alleged irregularities and money laundering in framing and implementing the Delhi Excise Policy 2022, which was later scrapped. Former Delhi minister Manish Sisodia and BRS leader K Kavitha are currently lodged in jail in connection with the same case.\\nUnlock a world of Benefits! From insightful newsletters to real-time stock tracking, breaking news and a personalized newsfeed – it\\'s all here, just a click away! Login Now!\\nCatch all the Business News, Market News, Events and Updates on Live Mint. Download The to get Daily Market Updates.',\n",
56
+ " 'Nifty Bank index opened 200 points higher and extended the gains as the day progress and inched closer to 49,000 mark.\\nOn the auspicious day of Gudi Padwa on April 9 , the Indian market climbed to fresh record high with the Nifty50 index crossing 22,750 for the first time with support from positive global cues.\\nThe index continued the previous session rally and touched fresh record high of 22,768.40 in the opening session and remained positive in the first half. However, selling in the second half erased all the gains to close the session with minor losses.\\nNifty ended 24.50 points, or 0.11 percent, lower at 22,641.80, from the previous close and formed a bearish candle on the daily chart.\\nDiscover the latest business news, Sensex, and Nifty updates. Obtain Personal Finance insights, tax queries, and expert opinions on Moneycontrol or download the Moneycontrol App to stay updated!\\nCopyright © e-Eighteen.com Ltd. All rights reserved. Reproduction of news articles, photos, videos or any other content in whole or in part in any form or medium without express writtern permission of moneycontrol.com is prohibited.',\n",
57
+ " ''],\n",
58
+ " 'scrape_errors': ['',\n",
59
+ " '',\n",
60
+ " '',\n",
61
+ " '',\n",
62
+ " 'Message: Malformed URL: URL constructor: 1 is not a valid URL.'],\n",
63
+ " 'summaries': ['Microsoft Corp will invest about $2.9 billion over the next two years to boost its artificial intelligence (AI) business in Japan, the Nikkei newspaper reports. The company also plans to announce an AI-related reskilling program in Japan to train 3 million workers over three years.',\n",
64
+ " 'A delegation of AAP leaders has met the top bench of the Indian Election Commission (EC) in Delhi.',\n",
65
+ " 'Aam Aadmi Party leader: \"We believe it will grant relief to CM Kejriwal\" Delhi High Court dismissed Kejriwal\\'s plea challenging arrest and remand by Enforcement Directorate. Kejriwal can go to the Supreme Court tomorrow itself.',\n",
66
+ " 'The Nifty50 index opened 200 points higher and extended the gains as the day progress. The index crossed 22,750 for the first time with support from positive global cues. Selling in the second half erased all the gains to close the session with minor losses.',\n",
67
+ " ''],\n",
68
+ " 'summarizer_error': ''}"
69
+ ]
70
+ },
71
+ "execution_count": 4,
72
+ "metadata": {},
73
+ "output_type": "execute_result"
74
+ }
75
+ ],
76
+ "source": [
77
+ "# Valid payload\n",
78
+ "payload = \\\n",
79
+ "{\n",
80
+ " \"urls\": [\n",
81
+ " \"https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445\",\n",
82
+ " \"https://www.thehindu.com/news/national/tmc-dharna-derek-obrien-saket-gokhale-others-continue-dharna-at-delhis-mandir-marg-police-station/article68046304.ece\",\n",
83
+ " \"https://www.livemint.com/news/india/arvind-kejriwal-will-move-supreme-court-sc-against-delhi-hcs-order-in-excise-policy-case-sources-11712660787632.html\",\n",
84
+ " \"https://www.moneycontrol.com/news/technicals/technical-view-nifty39s-record-rally-continues-crosses-22750-for-first-time-resistance-at-22740-22770_17520591.html\",\n",
85
+ " \"1\"\n",
86
+ " ],\n",
87
+ " \"key\": api_key\n",
88
+ "}\n",
89
+ "\n",
90
+ "r = requests.post(api_endpoint, json=payload)\n",
91
+ "\n",
92
+ "print(r.status_code)\n",
93
+ "r.json()"
94
+ ]
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "execution_count": 5,
99
+ "id": "3c9586df-8980-469e-9277-3d5e929eef43",
100
+ "metadata": {
101
+ "tags": []
102
+ },
103
+ "outputs": [
104
+ {
105
+ "name": "stdout",
106
+ "output_type": "stream",
107
+ "text": [
108
+ "500\n"
109
+ ]
110
+ },
111
+ {
112
+ "data": {
113
+ "text/plain": [
114
+ "{'urls': [],\n",
115
+ " 'scraped_texts': [],\n",
116
+ " 'scrape_errors': [],\n",
117
+ " 'summaries': '',\n",
118
+ " 'summarizer_error': 'error: list index out of range'}"
119
+ ]
120
+ },
121
+ "execution_count": 5,
122
+ "metadata": {},
123
+ "output_type": "execute_result"
124
+ }
125
+ ],
126
+ "source": [
127
+ "# Empty payload\n",
128
+ "payload = \\\n",
129
+ "{\n",
130
+ " \"urls\": [],\n",
131
+ " \"key\": api_key\n",
132
+ "}\n",
133
+ "\n",
134
+ "r = requests.post(api_endpoint, json=payload)\n",
135
+ "\n",
136
+ "print(r.status_code)\n",
137
+ "r.json()"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": 6,
143
+ "id": "a754e677-4dd1-477f-bbc9-f543a63b8394",
144
+ "metadata": {
145
+ "tags": []
146
+ },
147
+ "outputs": [
148
+ {
149
+ "name": "stdout",
150
+ "output_type": "stream",
151
+ "text": [
152
+ "422\n"
153
+ ]
154
+ },
155
+ {
156
+ "data": {
157
+ "text/plain": [
158
+ "{'detail': [{'type': 'list_type',\n",
159
+ " 'loc': ['body', 'urls'],\n",
160
+ " 'msg': 'Input should be a valid list',\n",
161
+ " 'input': 'https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445',\n",
162
+ " 'url': 'https://errors.pydantic.dev/2.6/v/list_type'}]}"
163
+ ]
164
+ },
165
+ "execution_count": 6,
166
+ "metadata": {},
167
+ "output_type": "execute_result"
168
+ }
169
+ ],
170
+ "source": [
171
+ "# Invalid payload\n",
172
+ "payload = \\\n",
173
+ "{\n",
174
+ " \"urls\": \"https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445\",\n",
175
+ " \"key\": api_key\n",
176
+ "}\n",
177
+ "\n",
178
+ "r = requests.post(api_endpoint, json=payload)\n",
179
+ "\n",
180
+ "print(r.status_code)\n",
181
+ "r.json()"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "execution_count": 7,
187
+ "id": "184356e3-bd51-4540-9c21-ee8b4d4f95b2",
188
+ "metadata": {
189
+ "tags": []
190
+ },
191
+ "outputs": [
192
+ {
193
+ "name": "stdout",
194
+ "output_type": "stream",
195
+ "text": [
196
+ "401\n"
197
+ ]
198
+ },
199
+ {
200
+ "data": {
201
+ "text/plain": [
202
+ "{'urls': ['https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445',\n",
203
+ " 'https://www.thehindu.com/news/national/tmc-dharna-derek-obrien-saket-gokhale-others-continue-dharna-at-delhis-mandir-marg-police-station/article68046304.ece',\n",
204
+ " 'https://www.livemint.com/news/india/arvind-kejriwal-will-move-supreme-court-sc-against-delhi-hcs-order-in-excise-policy-case-sources-11712660787632.html',\n",
205
+ " 'https://www.moneycontrol.com/news/technicals/technical-view-nifty39s-record-rally-continues-crosses-22750-for-first-time-resistance-at-22740-22770_17520591.html',\n",
206
+ " '1'],\n",
207
+ " 'scraped_texts': '',\n",
208
+ " 'scrape_errors': '',\n",
209
+ " 'summaries': '',\n",
210
+ " 'summarizer_error': 'error: Authentication error: Invalid API key.'}"
211
+ ]
212
+ },
213
+ "execution_count": 7,
214
+ "metadata": {},
215
+ "output_type": "execute_result"
216
+ }
217
+ ],
218
+ "source": [
219
+ "# Invalid key\n",
220
+ "payload = \\\n",
221
+ "{\n",
222
+ " \"urls\": [\n",
223
+ " \"https://www.zeebiz.com/technology/news-microsoft-to-invest-29-billion-to-boost-ai-business-in-japan-nikkei-283445\",\n",
224
+ " \"https://www.thehindu.com/news/national/tmc-dharna-derek-obrien-saket-gokhale-others-continue-dharna-at-delhis-mandir-marg-police-station/article68046304.ece\",\n",
225
+ " \"https://www.livemint.com/news/india/arvind-kejriwal-will-move-supreme-court-sc-against-delhi-hcs-order-in-excise-policy-case-sources-11712660787632.html\",\n",
226
+ " \"https://www.moneycontrol.com/news/technicals/technical-view-nifty39s-record-rally-continues-crosses-22750-for-first-time-resistance-at-22740-22770_17520591.html\",\n",
227
+ " \"1\"\n",
228
+ " ],\n",
229
+ " \"key\": \"api_key\"\n",
230
+ "}\n",
231
+ "\n",
232
+ "r = requests.post(api_endpoint, json=payload)\n",
233
+ "\n",
234
+ "print(r.status_code)\n",
235
+ "r.json()"
236
+ ]
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "execution_count": null,
241
+ "id": "94916ebe-a75b-446e-affd-9d139841cc08",
242
+ "metadata": {},
243
+ "outputs": [],
244
+ "source": []
245
+ }
246
+ ],
247
+ "metadata": {
248
+ "kernelspec": {
249
+ "display_name": "Python 3 (ipykernel)",
250
+ "language": "python",
251
+ "name": "python3"
252
+ },
253
+ "language_info": {
254
+ "codemirror_mode": {
255
+ "name": "ipython",
256
+ "version": 3
257
+ },
258
+ "file_extension": ".py",
259
+ "mimetype": "text/x-python",
260
+ "name": "python",
261
+ "nbconvert_exporter": "python",
262
+ "pygments_lexer": "ipython3",
263
+ "version": "3.11.5"
264
+ }
265
+ },
266
+ "nbformat": 4,
267
+ "nbformat_minor": 5
268
+ }