ppsingh commited on
Commit
a7d1ac5
β€’
1 Parent(s): 3c4b33d

policy download

Browse files
Files changed (1) hide show
  1. appStore/policyaction.py +108 -75
appStore/policyaction.py CHANGED
@@ -293,6 +293,39 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
293
  st.session_state['action_hits'] = df
294
 
295
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
297
  #count_ghg = sum(hits['GHG Label'] == 'GHG')
298
  #count_economy = sum([True if 'Economy-wide' in x else False
@@ -363,82 +396,82 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
363
  # st.info("πŸ€” No Actions found")
364
 
365
 
366
- def policy_display():
367
- if 'key1' in st.session_state:
368
- df = st.session_state.key1
369
 
370
 
371
- df['Policy_check'] = df['Policy-Action Label'].apply(lambda x: True if 'Policies & Plans' in x else False)
372
- hits = df[df['Policy_check'] == True]
373
- # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
374
- range_val = min(5,len(hits))
375
- if range_val !=0:
376
- count_policy = len(hits)
377
- #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
378
- #count_ghg = sum(hits['GHG Label'] == 'GHG')
379
- #count_economy = sum([True if 'Economy-wide' in x else False
380
- # for x in hits['Sector Label']])
381
 
382
- # count_df = df['Target Label'].value_counts()
383
- # count_df = count_df.rename('count')
384
- # count_df = count_df.rename_axis('Target Label').reset_index()
385
- # count_df['Label_def'] = count_df['Target Label'].apply(lambda x: _lab_dict[x])
386
-
387
- # fig = px.bar(count_df, y="Label_def", x="count", orientation='h', height=200)
388
- # c1, c2 = st.columns([1,1])
389
- # with c1:
390
- # st.write('**Target Paragraphs**: `{}`'.format(count_target))
391
- # st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
392
- #
393
- # # st.plotly_chart(fig,use_container_width= True)
394
- #
395
- # count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
396
- # count_ghg = sum(hits['GHG Label'] == 'LABEL_2')
397
- # count_economy = sum([True if 'Economy-wide' in x else False
398
- # for x in hits['Sector Label']])
399
- # with c2:
400
- # st.write('**GHG Related Paragraphs**: `{}`'.format(count_ghg))
401
- # st.write('**Economy-wide Related Paragraphs**: `{}`'.format(count_economy))
402
- # st.write('-------------------')
403
- # hits = hits.sort_values(by=['Relevancy'], ascending=False)
404
- # netzerohit = hits[hits['Netzero Label'] == 'NETZERO']
405
- # if not netzerohit.empty:
406
- # netzerohit = netzerohit.sort_values(by = ['Netzero Score'], ascending = False)
407
- # # st.write('-------------------')
408
- # st.markdown("###### Netzero paragraph ######")
409
- # st.write('**Netzero paragraph** `page {}`: {}'.format(netzerohit.iloc[0]['page'],
410
- # netzerohit.iloc[0]['text'].replace("\n", " ")))
411
- # st.write("")
412
- # else:
413
- # st.info("πŸ€” No Netzero paragraph found")
414
-
415
- # st.write("**Result {}** `page {}` (Relevancy Score: {:.2f})'".format(i+1,hits.iloc[i]['page'],hits.iloc[i]['Relevancy'])")
416
- # st.write('-------------------')
417
- st.write("")
418
- st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
419
- st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
420
- range_val = min(5,len(hits))
421
- for i in range(range_val):
422
- # the page number reflects the page that contains the main paragraph
423
- # according to split limit, the overlapping part can be on a separate page
424
- st.write('**Result {}** : `page {}`, `Sector: {}`,\
425
- `Indicators: {}`, `Adapt-Mitig :{}`'\
426
- .format(i+1,
427
- hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
428
- hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))
429
- st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
430
- hits = hits.reset_index(drop =True)
431
- st.write('----------------')
432
- st.write('Explore the data')
433
- st.write(hits)
434
- df.drop(columns = ['Policy_check'],inplace=True)
435
- df_xlsx = to_excel(df)
436
 
437
- with st.sidebar:
438
- st.write('-------------')
439
- st.download_button(label='πŸ“₯ Download Result',
440
- data=df_xlsx ,
441
- file_name= os.path.splitext(st.session_state['filename'])[0]+'.xlsx')
442
-
443
- else:
444
- st.info("πŸ€” No Policy/Plans found")
 
293
  st.session_state['action_hits'] = df
294
 
295
  return
296
+ def policy_display():
297
+ if 'key1' in st.session_state:
298
+ df = st.session_state.key1
299
+ st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
300
+ .format(os.path.basename(st.session_state['filename']),
301
+ len(df)))
302
+ hits = df[df['Policies_Plans Label'] == 'Policy and Plans']
303
+ range_val = min(5,len(hits))
304
+ if range_val !=0:
305
+ count_action = len(hits)
306
+ hits.drop(columns=['Target Label','Target Score','Netzero Score',
307
+ 'Netzero Label','GHG Label',
308
+ 'GHG Score','Action Label','Policies_Plans Label',
309
+ 'Action Score','Conditional Score'],inplace=True)
310
+ hits = hits.sort_values(by=['Action Score'], ascending=False)
311
+ hits = hits.reset_index(drop=True)
312
+
313
+ st.write('----------------')
314
+
315
+
316
+ st.caption("Filter table to select rows to keep for Policies and Plans category")
317
+ filter_dataframe(hits)
318
+ # filtered_df = filtered_df[filtered_df.keep == True]
319
+ # st.write('Explore the data')
320
+ # AgGrid(hits)
321
+
322
+
323
+ with st.sidebar:
324
+ st.write('-------------')
325
+ df_xlsx = to_excel(df)
326
+ st.download_button(label='πŸ“₯ Download Result',
327
+ data=df_xlsx ,
328
+ file_name= os.path.splitext(os.path.basename(st.session_state['filename']))[0]+'.xlsx')
329
  #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
330
  #count_ghg = sum(hits['GHG Label'] == 'GHG')
331
  #count_economy = sum([True if 'Economy-wide' in x else False
 
396
  # st.info("πŸ€” No Actions found")
397
 
398
 
399
+ # def policy_display():
400
+ # if 'key1' in st.session_state:
401
+ # df = st.session_state.key1
402
 
403
 
404
+ # df['Policy_check'] = df['Policy-Action Label'].apply(lambda x: True if 'Policies & Plans' in x else False)
405
+ # hits = df[df['Policy_check'] == True]
406
+ # # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
407
+ # range_val = min(5,len(hits))
408
+ # if range_val !=0:
409
+ # count_policy = len(hits)
410
+ # #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
411
+ # #count_ghg = sum(hits['GHG Label'] == 'GHG')
412
+ # #count_economy = sum([True if 'Economy-wide' in x else False
413
+ # # for x in hits['Sector Label']])
414
 
415
+ # # count_df = df['Target Label'].value_counts()
416
+ # # count_df = count_df.rename('count')
417
+ # # count_df = count_df.rename_axis('Target Label').reset_index()
418
+ # # count_df['Label_def'] = count_df['Target Label'].apply(lambda x: _lab_dict[x])
419
+
420
+ # # fig = px.bar(count_df, y="Label_def", x="count", orientation='h', height=200)
421
+ # # c1, c2 = st.columns([1,1])
422
+ # # with c1:
423
+ # # st.write('**Target Paragraphs**: `{}`'.format(count_target))
424
+ # # st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
425
+ # #
426
+ # # # st.plotly_chart(fig,use_container_width= True)
427
+ # #
428
+ # # count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
429
+ # # count_ghg = sum(hits['GHG Label'] == 'LABEL_2')
430
+ # # count_economy = sum([True if 'Economy-wide' in x else False
431
+ # # for x in hits['Sector Label']])
432
+ # # with c2:
433
+ # # st.write('**GHG Related Paragraphs**: `{}`'.format(count_ghg))
434
+ # # st.write('**Economy-wide Related Paragraphs**: `{}`'.format(count_economy))
435
+ # # st.write('-------------------')
436
+ # # hits = hits.sort_values(by=['Relevancy'], ascending=False)
437
+ # # netzerohit = hits[hits['Netzero Label'] == 'NETZERO']
438
+ # # if not netzerohit.empty:
439
+ # # netzerohit = netzerohit.sort_values(by = ['Netzero Score'], ascending = False)
440
+ # # # st.write('-------------------')
441
+ # # st.markdown("###### Netzero paragraph ######")
442
+ # # st.write('**Netzero paragraph** `page {}`: {}'.format(netzerohit.iloc[0]['page'],
443
+ # # netzerohit.iloc[0]['text'].replace("\n", " ")))
444
+ # # st.write("")
445
+ # # else:
446
+ # # st.info("πŸ€” No Netzero paragraph found")
447
+
448
+ # # st.write("**Result {}** `page {}` (Relevancy Score: {:.2f})'".format(i+1,hits.iloc[i]['page'],hits.iloc[i]['Relevancy'])")
449
+ # # st.write('-------------------')
450
+ # st.write("")
451
+ # st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
452
+ # st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
453
+ # range_val = min(5,len(hits))
454
+ # for i in range(range_val):
455
+ # # the page number reflects the page that contains the main paragraph
456
+ # # according to split limit, the overlapping part can be on a separate page
457
+ # st.write('**Result {}** : `page {}`, `Sector: {}`,\
458
+ # `Indicators: {}`, `Adapt-Mitig :{}`'\
459
+ # .format(i+1,
460
+ # hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
461
+ # hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))
462
+ # st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
463
+ # hits = hits.reset_index(drop =True)
464
+ # st.write('----------------')
465
+ # st.write('Explore the data')
466
+ # st.write(hits)
467
+ # df.drop(columns = ['Policy_check'],inplace=True)
468
+ # df_xlsx = to_excel(df)
469
 
470
+ # with st.sidebar:
471
+ # st.write('-------------')
472
+ # st.download_button(label='πŸ“₯ Download Result',
473
+ # data=df_xlsx ,
474
+ # file_name= os.path.splitext(st.session_state['filename'])[0]+'.xlsx')
475
+
476
+ # else:
477
+ # st.info("πŸ€” No Policy/Plans found")