DMA / PNSA /8 /__01__.py
KVNAditya's picture
__0_0_0__
65e8f87 verified
raw
history blame
5.29 kB
"""
Personalized News Summarization Assistant with LangChain :: https://o-0268-kvnaditya-8620-o.web.app/documentation/pnsa.html
{ K.V.N. Aditya | P. Sai Karthik | P. Phanindra | M. Venu | B. Lokesh }
SurgeClasses || CMR Technical Campus
"""
import os
import newspaper #[logs]::internal module dependency for NewsURLLoader
import translators as ts
import gnewsclient.gnewsclient as gnewsclient
from langchain_community.document_loaders import NewsURLLoader
from shiny import ui, App, run_app, reactive, render
from multiprocessing import Process, freeze_support
DMA__PNSA = os.path.abspath('PNSA').replace('\\', '/')
def __0__(args__opt):
config__ts_langs = {'english' : 'en','telugu' : 'te','hindi' : 'hi'}
lst__ul__gnc_nc = []
lst__url_tle_despn_smry = []
config__gnc_nc = gnewsclient.NewsClient(location=args__opt[0],topic=args__opt[1],max_results=int(args__opt[3]))
for itr_nc in range(int(args__opt[3])):
try:
lst__ul__gnc_nc.append(config__gnc_nc.get_news()[itr_nc]['link'])
except:
pass
config__lc_nul = NewsURLLoader(lst__ul__gnc_nc,nlp=True)
for itr in enumerate(config__lc_nul.load()):
itr_lst__url_tle_despn_smry = []
itr_lst__url_tle_despn_smry.append(ts.translate_text(itr[1].metadata['title'],translator='google',from_language='auto',to_language=config__ts_langs[args__opt[2]]))
itr_lst__url_tle_despn_smry.append(ts.translate_text('description'+' : '+itr[1].metadata['description'],translator='google',from_language='auto',to_language=config__ts_langs[args__opt[2]]))
itr_lst__url_tle_despn_smry.append(ts.translate_text('summary'+' : '+itr[1].metadata['summary'],translator='google',from_language='auto',to_language=config__ts_langs[args__opt[2]]))
lst__url_tle_despn_smry.append((lst__ul__gnc_nc[itr[0]],itr_lst__url_tle_despn_smry))
return lst__url_tle_despn_smry
def __8__(_ip_,_op_,_io_):
rv__op = reactive.Value(None)
@reactive.Effect
@reactive.event(_ip_.id_iab__pnsa)
def rv__op__pnsa():
io = __0__([_ip_.id_is__opt_locs(),_ip_.id_is__opt_tpcs(),_ip_.id_is__opt_langs(),_ip_.id_in__opt_n_count()])
n = len(io)
p = ""
p += f'<br>'
p += f"<div id='id_div__pnsa__op_op'>"
for itr in io:
despn = itr[1][1].index(':')
smry = itr[1][2].index(':')
head__despn = itr[1][1][:despn]
body__despn = itr[1][1][despn:]
head__smry = itr[1][2][:smry]
body__smry = itr[1][2][smry:]
if(len(itr[1][0]) != 0):
p += f'<a id="id_a__pnsa__op_title" href="{itr[0]}">{itr[1][0]}</a>'
if(len(itr[1][1]) != 0):
p += f"<br>"
p += f"<b>{head__despn}</b>"
p += f"{body__despn}"
if(len(itr[1][2]) != 0):
p += f"<br>"
p += f"<b>{head__smry}</b>"
p += f"{body__smry}"
n -= 1
if(n != 0):
p += f"<hr>"
p += f"</div>"
p += f'<br>'
rv__op.set(ui.HTML(p))
@_op_
@render.ui
def id_ou__pnsa():
return rv__op()
def __1__():
config__gnc_nc = gnewsclient.NewsClient()
lst_gnc_nc_locs = [None]+sorted(config__gnc_nc.locations)
lst_gnc_nc_tpcs = [None]+sorted(config__gnc_nc.topics)
lst_gnc_nc_langs = [None]+sorted(config__gnc_nc.languages)
lst_gnc_nc_langs = [None]+sorted(['english','telugu','hindi'])
return \
ui.page_fluid(
ui.br(),
ui.tags.title('Personalized News Summarization Assistant'),
ui.include_css(f'{DMA__PNSA}/8/__/_01_.css'),
ui.div(
ui.h3('Personalized News Summarization Assistant'),
ui.br(),
ui.p('{K.V.N.Aditya | P.Sai Karthik | P.Phanindra | M.Venu | B.Lokesh Reddy}'),
ui.p('SurgeClasses || CMR Technical Campus'),
ui.hr(),
id = 'id_div__pnsa__head'
),
ui.div(
ui.div(
ui.input_selectize('id_is__opt_locs','location',lst_gnc_nc_locs,options={'placeholder':'location'}),
ui.input_selectize('id_is__opt_tpcs','topic',lst_gnc_nc_tpcs,options={'placeholder':'topic'}),
ui.input_selectize('id_is__opt_langs','language',lst_gnc_nc_langs,options={'placeholder':'language'}),\
ui.input_numeric('id_in__opt_n_count','news count',min=1,max=20,step=1,value=2),
id = 'id_div__pnsa__ip'
),
ui.div(
ui.input_action_button('id_iab__pnsa','PNSA'),
id = 'id_div__pnsa__p'
),
id = 'id_div__pnsa__ip_p'
),
ui.div(
ui.div(
ui.output_ui('id_ou__pnsa'),
id = 'id_div__pnsa__op'
)
),
ui.br()
)
_081_ = App(__1__(), __8__)
if __name__ == '__main__':
freeze_support()
Process(target=run_app(f'__01__:_081_',host='127.0.0.1',port=8000, reload=True)).start() # (required) || < (reload=True) :: for debugging >
else:
...