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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
import streamlit as st   ### importing liberaries
from streamlit_extras.colored_header import colored_header
from streamlit_option_menu import option_menu
import streamlit.components.v1 as component
from streamlit_lottie import st_lottie, st_lottie_spinner
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
from transformers import pipeline
from transformers import AutoTokenizer , AutoModelForSeq2SeqLM
from newspaper import Article
import nltk
import nltk.downloader
nltk.download('punkt_tab')
from nltk.tokenize import word_tokenize
from cleantext import clean
from PyPDF2 import PdfReader
import pdfminer
from pdfminer.high_level import extract_text
from pdfminer.high_level import extract_pages
from pdfminer.layout import LTTextContainer, LTChar, LTTextLine
import requests
import json
import numpy as np
import pandas as pd
import random
import base64
import lxml
import lxml_html_clean
import re
import os


###### main app functions

### insert external css
def insert_css(css_file:str):
    with open(css_file) as f:
        st.markdown(f"<style>{f.read()}</style>",unsafe_allow_html=True)

### insert external html file
def insert_html(html_file):
    with open(html_file) as f:
        return f.read()

### insert lottie animation json files
def insert_lottie_animation(animation_file:str):
    with open(animation_file, "r") as f:
        return json.load(f)

### app tutorial video function
@st.dialog("App Tutorial")
def watch_tutorial():
    st.subheader("GenAi Summarizer🤖")
    video_file = open("app_tutorial.mp4", "rb")
    video_bytes = video_file.read()
    st.text("")
    st.video(
        data=video_bytes,format="video/mp4",
        loop=True,autoplay=True
    )


def download_text(text, filename):
    """
    download article text 
    in document format
    """
    #### Convert string to bytes
    b64 = base64.b64encode(text.encode()).decode()

    href = f"""
            <a href="data:application/octet-stream;base64,{b64}" download="{filename}">
                <button class="neon-button">Download</button>
            </a>
            """
    
    st.markdown(href, unsafe_allow_html=True)
    if __name__=="__main__":
        insert_css("cssfiles/download-article.css")


def copy_text(text):
    html_code = f"""
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
             <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
            <style>
                *{{
                    margin: 0;
                    padding: 0;
                    box-sizing: border-box;
                }}
                .copy-button{{
                    font-size: 24px;
                    cursor: pointer;
                    color: #5b70f3;
                    transition: 0.3s ease-in-out;
                }}
            </style>
        </head>
        <body>
            <a class="copy-button" onclick="copyText()">
                <i class="fa-solid fa-copy"></i>
            </a>
            <br>
            <br>
            <p id="textToCopy">{text}</p>

            <script>
                function copyText() {{
                    // Get the text from the <p> tag
                    const text = document.getElementById('textToCopy').innerText;

                    // Create a temporary <textarea> element
                    const textarea = document.createElement('textarea');
                    textarea.value = text;
                    document.body.appendChild(textarea);

                    // Select the text in the <textarea>
                    textarea.select();

                    // Execute the copy command
                    document.execCommand('copy');

                    // Remove the <textarea> element from the DOM
                    document.body.removeChild(textarea);

                    alert('Text copied');
                }}
            </script>
        </body>
        </html>

    """

    component.html(html_code,height=28)


### copy and download button
def Copy_download_button(article_text,article_format,article_file_name):
    try:
                ### column for copy and download article
        Copy_btn_col,download_btn_col, blank_col_copy1, blank_col_copy2= st.columns([1,3,5,5],gap="small")

        with blank_col_copy1:
            st.text("")
        with blank_col_copy1:
            st.text("")
                
        with Copy_btn_col:
            copy_text(article_text)

        with download_btn_col:
            download_text(text=article_format,filename=article_file_name)
    except Exception as e:
        st.warning("Something went wrong...",e,icon="⚠️")


### setting page layout
st.set_page_config( 
    page_title="GenAi Summarizer",
    page_icon="🤗",
    initial_sidebar_state="collapsed",
    layout="wide"
)


#### app settings css
if __name__=="__main__":
    insert_css("cssfiles/app.css")   


### huging face modals
Hugingface_modals = {
    "google-pegasus":"google/pegasus-xsum",
    "facebook-bart":"facebook/bart-large-cnn",
    "t5-base":"t5-base"
}


### summarization modal
def Hugingface_summarization_modal(summary_text,modal_name,maximum_length):
    """
    it is an text summarization modal
    it use hugingface modals for summarization task.
    it generates summarized text output
    """
    def summarization_modal_name(modal)->str:
        if modal == "google-pegasus":
            return "google/pegasus-xsum"
        elif modal == "facebook-bart":
            return "facebook/bart-large-cnn"
        elif modal == "t5-base":
            return "t5-base"
    try:
        use_modal = summarization_modal_name(modal_name)  ### modal name

        auto_tokenizer = AutoTokenizer.from_pretrained(use_modal) ### using autokenizer for pretrained modal
        auto_modal = AutoModelForSeq2SeqLM.from_pretrained(use_modal)

        ### creating pipeline
        summarizer = pipeline("summarization",model=auto_modal,tokenizer=auto_tokenizer)

        summarizer_text = summary_text

        summary_generate = summarizer( ### summarizer
            summarizer_text,max_length=maximum_length+20,
            min_length=maximum_length,
            do_sample=False
        ) 

        return summary_generate[0]['summary_text']
            
    except Exception as e:
        st.warning("Something went wrong...\n\n",e,icon="⚠️")




### displaying modals
@st.cache_data
def Modal_Level(modal_text):
    if modal_text == "google-pegasus":
        st.markdown(
            f"""
                <div class="google-modal">
                <span style="font-size: 17px; color: #fff;">
                    Maodal-
                </span>
                    google/pegasus-xsum
                </div>
            """,unsafe_allow_html=True
        )

    elif modal_text == "facebook-bart":
        st.markdown(
            f"""<div class="facebook-modal">
                <span style="font-size: 17px; color: #fff;">
                    Maodal-
                </span>
                    facebook/bart-large-cnn
                </div>
            """,unsafe_allow_html=True
        )

    elif modal_text == "t5-base":
        st.markdown(
            f"""<div class="t5-modal">
                <span style="font-size: 17px; color: #fff;">
                    Maodal-
                </span>
                    t5-base
                </div>
            """,unsafe_allow_html=True
        )
    if __name__=="__main__":
        insert_css("cssfiles/modal.css")



#### creating sidebar
app_sidebar = st.sidebar

with app_sidebar:
    st.text("")
    st.subheader("GenAi Summarizer🤖")
    st.write("Developer: **Nishant Maity**")
    st.text("")
    st.text("")

    ### creating menu bar
    Main_menu = option_menu(
        menu_title="",
        options=["Article Summarizer","Text Summarizer","PDF Summarizer","App Info"],
        icons=["chat-dots","card-heading","file-earmark-pdf","person-circle"],
        default_index=0,
        key="Menu Bar"
    )
    st.text("")

    ### select modal for text and article summarizer
    if Main_menu == "Article Summarizer" or Main_menu == "Text Summarizer":

        Summarizer_modal = st.selectbox(
            label="Select Modal",
            options=np.array(list(Hugingface_modals.keys())),
            index=1,
            key="Modals"
        )

#### selecting number or paragraph for article summarizer
if Main_menu == "Article Summarizer":
    with app_sidebar:
        st.text("")
        st.text("")

        Number_of_article_paragraph = st.slider(
            label="Number of paragraph",
            min_value=1,max_value=10,
            step=1,value=2,
            key="Number of paragraph"
        )

with app_sidebar:
    st.button(
        label="Watch App Tutorial",
        use_container_width=True,
        on_click=watch_tutorial
    )


##### article summarizer functions

##### naive bayes text classification function

def is_url(text):
    url_pattern = re.compile(
        r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+|(?:www\.)[^\s]+')
    return bool(url_pattern.match(text))


# Train a model for text vs URL classification
def train_model():
    """
    this function predict the given input
    is a simple text or url,link 
    and generate output.
    """
    #### dataset (normal text and URLs)
    try:
        data = [
            ('This is a normal sentence.', 'text'),
            ('www.google.com', 'url'),
            ('Check out this website', 'text'),
            ('https://www.example.com', 'url'),
            ('Machine learning is fun', 'text'),
            ('http://openai.com', 'url'),
            ('Python is a great language', 'text'),
        ]
        texts = [d[0] for d in data]
        labels = [1 if d[1] == 'url' else 0 for d in data]  ## 1 for url, 0 for text
        
        ##### modal training
        X_train, X_test, y_train, y_test = train_test_split(texts, labels, test_size=0.2, random_state=42)
        
        model = make_pipeline(CountVectorizer(), MultinomialNB())
        
        model.fit(X_train, y_train)   #### Train the model
        
        model.score(X_train, y_train)
        model.score(X_test, y_test)
        
        return model
    
    except Exception as e:
        st.error("Error...\n\n",e,icon="⚠️")



###############################    article summarizer


if Main_menu == "Article Summarizer":

    blank_article1, article_column, blank_article2 = st.columns([2,8,2],gap="small")

    with blank_article1:  ### blank space
        pass
    with blank_article2:  ### blank space
        pass

    #### main app column
    with article_column:
        
        #### app title
        st.text("")
        App_Title = colored_header(
            label="Web Article Summarizer 📑",
            color_name="blue-green-70",
            description="Search or paste url"
        )
  
        Text_input = st.text_input(
                label="Search or paste url",
                placeholder="machine learning, java  url- https://www.example.com"
        )  
        
        ### max slider value
        def max_length_slider_value(max_length)->int:
            if max_length == 1:
                return 90
            elif max_length == 2:
                return 150
            elif max_length == 3:
                return 250
            elif max_length == 4:
                return 380
            elif max_length == 5:
                return 470
            elif max_length == 6:
                return 600
            elif max_length == 7:
                return 750
            elif max_length == 8:
                return 900
            elif max_length == 9:
                return 1200
            elif max_length == 10:
                return 1360
        
        @st.cache_data
        def Default_max_length(default_value):
            if default_value == 1:
                random_value = np.random.randint(30,65,6)
                return random.choice(random_value)
            
            elif default_value == 2:
                random_value = np.random.randint(50,130,6)
                return random.choice(random_value)
            
            elif default_value == 3:
                random_value = np.random.randint(70,210,6)
                return random.choice(random_value)
            
            elif default_value == 4:
                random_value = np.random.randint(140,310,6)
                return random.choice(random_value)
            
            elif default_value == 5:
                random_value = np.random.randint(200,390,6)
                return random.choice(random_value)
            
            elif default_value == 6:
                random_value = np.random.randint(230,490,6)
                return random.choice(random_value)
            
            elif default_value == 7:
                random_value = np.random.randint(280,590,6)
                return random.choice(random_value)
            
            elif default_value == 8:
                random_value = np.random.randint(350,750,6)
                return random.choice(random_value)
            
            elif default_value == 9:
                random_value = np.random.randint(450,1050,6)
                return random.choice(random_value)
            
            elif default_value == 10:
                random_value = np.random.randint(560,1100,6)
                return random.choice(random_value)

            

        
        Button_column, Toggle_summary_btn, Modal_display = st.columns([1,1,3],gap="small")  

        
        # article_summarizer(max_length)
        with Button_column:
        ### generate article button
            Generate_btn = st.button(label="Generate Article")

        with Toggle_summary_btn:
            ### if on then it generates summary
            summary_on = st.toggle(
                label="Summarizer",
                value=False,
                key="Summarizer on off"
            )

            if summary_on:
                st.toast(body="Summarizer Mode on",icon="📑")
            else:
                st.toast(body="Scraping Mode",icon="📰")
            
        with Modal_display:
            
            if summary_on:
                Modal_Level(Summarizer_modal)  
            else:
                pass          
        if summary_on:
            max_length_article = st.slider(
                label="max length",
                min_value=10,max_value=max_length_slider_value(Number_of_article_paragraph),
                key="max length",value=Default_max_length(Number_of_article_paragraph)
            ) 
        

################################################################################################

        
        ### article scraper function
        def article_scraper(article_url):
            """
            this function is used to scrap
            web articles and it provide
            text in the clean format
            """
            try:
                article = Article(article_url)  ### article object
                article.download()
                article.parse()
                nltk.download("punkt")
                article.nlp()

                st.markdown("<h4>Article</h4>",unsafe_allow_html=True)
                st.text("")
                st.text("")

                st.markdown(   ### article title
                    f"""
                        <h6><b>{article.title}</b></h6>
                    """,unsafe_allow_html=True
                )

                article_publishdate = article.publish_date   ### article publish date
                if article_publishdate == None:
                    pass
                else:
                    st.text("published on - "+str(article_publishdate))
                
                article_authors = article.authors   #### article authors
                if len(article_authors) == 0:
                    pass
                else:
                    autho_name_print = ", ".join(map(str, article_authors))
                    st.write(autho_name_print)

                
                ### generating article summary
                def get_top_paragraphs(text, num_paragraphs=Number_of_article_paragraph):
                    """
                    this function gives
                    top 1 - 10 paragraph of the 
                    scrap data
                    """
                    paragraphs = text.split('\n\n')

                    valid_paragraphs = [p.strip() for p in paragraphs if len(p.strip().split()) > 12]
                    top_paragraphs = valid_paragraphs[:num_paragraphs]
                    return '\n\n'.join(top_paragraphs)


                article_summary = article.text

                def remove_bracketed_numbers(text)->str:
                    pattern = r'\[\d+\]'
                    cleaned_text = re.sub(pattern, '', text)
                    return cleaned_text

                
                cleaned_article_text = remove_bracketed_numbers(get_top_paragraphs(article_summary))

                if "clean_text" not in st.session_state:
                    st.session_state.clean_text = ""

                st.session_state.clean_text = cleaned_article_text

                def clean_output_text(text:str)->str:
                    """
                    it gives clean text without emojies,
                    no ascii values english text
                    """
                    clean_text = clean(
                        text=text,fix_unicode=True,
                        to_ascii=True,no_emoji=True,
                        lang="en",no_line_breaks=False,
                        keep_two_line_breaks=True
                    )
                    return clean_text
                ### Print the cleaned text
                st.write(clean_output_text(st.session_state.clean_text))
                st.text("")
                st.text("")


                ### copy download button
                Article_filename = f"{article.title}.doc"

                Article_text_format = f"""
                    \n\n\n
{str(article.title)}
published on - {str(article_publishdate)}
Authors - {", ".join(map(str, article_authors))}
        \n\n\n
{str(cleaned_article_text)}
                """

                
                if __name__=="__main__":
                    Copy_download_button(
                        article_text=clean_output_text(cleaned_article_text),
                        article_format=Article_text_format,
                        article_file_name=Article_filename
                    )
                    
                st.text("")
                
                if summary_on:
                    st.markdown("<h4>Article Summary</h4>",unsafe_allow_html=True)

                    #### summarization modal

                    with st.spinner("Generating Summary..."):

                        
                        if __name__=="__main__":
                            summarized_article_text = Hugingface_summarization_modal(
                                summary_text=clean_output_text(cleaned_article_text),
                                modal_name=Summarizer_modal,
                                maximum_length=max_length_article
                            )
                            #### clean ai generated paragraph
                            

                            st.write(summarized_article_text)
                            st.text("")
                            st.text("")

                            summary_format = f"""

\n\n
{article.title}
\n\n\n
{summarized_article_text}
"""
                            #### copy or download summary button
                            if __name__=="__main__":
                                Copy_download_button(
                                    article_text=summarized_article_text,
                                    article_file_name=f"{article.title}-summary.doc",
                                    article_format=summary_format
                                )
                
                if summary_on:

                    ### summarization details
                    summarization_details = {
                        "Summarization Details":["Modal Name","Text Length","Summary Length","Max Tokens"],
                        "Output":[
                            f"{Summarizer_modal}",
                            f"Length - {len(cleaned_article_text.split())}",
                            f"Length - {len(summarized_article_text.split())}",
                            f"Tokens Used - {max_length_article}"
                        ]
                    }

                    summarization_details_df = pd.DataFrame(
                        data=summarization_details,
                        index=["Hugingface Modal","No. words","No. Words","Max Length"]
                    )

                    st.text("")
                    st.text("")
                    st.text("")
                    st.dataframe(summarization_details_df,use_container_width=True)
                        


            except Exception as err:
                ### 404 error animation

                Error_404_col, page_not_found_col = st.columns(2)

                with Error_404_col:

                    try:
                        Error_404 = insert_lottie_animation("lottie_animations/error-404.json")
                        st_lottie(
                            animation_source=Error_404,
                            speed=1,
                            reverse=False,loop=True,
                            quality="high",
                            height=315,
                            width=400,
                            key="404 error"
                        )
                    except Exception as err:
                        st.warning("something went wrong...",err,icon="⚠️")

                with page_not_found_col:    
                    
                    try:
                        page_not_found = insert_lottie_animation("lottie_animations/page-not-found.json")
                        st_lottie(
                            animation_source=page_not_found,
                            speed=1,
                            reverse=False,loop=True,
                            quality="high",
                            height=265,
                            width=400,
                            key="page not found"
                        )
                    except Exception as err:
                        st.warning("something went wrong...",err,icon="⚠️")

                st.warning(f"Something went wrong...\n\n{err}",icon="⚠️")

        def article_summarizer(summary_length):
            st.write(summary_length)

        
        def check_url_exists(url):
            try:
                response = requests.head(url, allow_redirects=True)
                if response.status_code < 400:
                    return True
                else:
                    return False
            except requests.exceptions.RequestException as e:
                # Handle any exception (e.g., connection error, timeout)
                return False


        ###########      link classified article
        def link_classified(text):
            """
            it use url or link to scrap articles
            provide author name, publish date, summary of
            article
            """
            try:
                url_text = text
                article_url_link = f"{url_text}" ### url to scrap
                if __name__=="__main__":
                    article_scraper(article_url_link)
                    st.text("")
                    st.text("")

                    if check_url_exists(article_url_link):
                        st.link_button(label="Visit Article",url=(article_url_link))
                    else:
                        st.warning("Url does not exist...",icon="⚠️")

                    st.text("")
                    st.text("")
                    st.text("")
                    st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)

            except Exception as err:
                st.warning(f"Something went wrong...\n\n{err}",icon="⚠️")



        ####$     text classified article
        def text_classified(text):
            """
            it use wikipedia to scrap articles
            provide author name, publish date, summary of
            article
            """
            try:
                url_text = text.replace(" ","_")
                article_url = f"https://en.wikipedia.org/wiki/{url_text}" ### url to scrap
                if __name__=="__main__":
                    article_scraper(article_url)
                    st.text("")
                    st.text("")

                    if check_url_exists(article_url):
                        st.link_button(label="Visit Article",url=article_url)
                    else:
                        st.warning("Url does not exist...",icon="⚠️")

                    st.text("")
                    st.text("")
                    st.text("")
                    st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)


            except Exception as e:
                st.warning("Something went wrong...",e,icon="⚠️")

        

############################################################################################
        
        ### j query animation
        if not Generate_btn or Text_input.strip() == "":
            
            try:
                def particle(Js_file):
                    with open(Js_file) as f:
                        component.html(f"{f.read()}", height=420)

                if __name__=="__main__":
                    particle("animation/particles.html")
        
            except Exception as e:
                st.error("Something went wrong...\n\n",e)

        if Generate_btn:
            if Text_input.strip() != "":
                st.text("")
                st.text("")

                ### Function to classify the input text
                def classify_input(text, model):
                    try:
                        if is_url(text):
                            link_classified(text)
                        else:
                            #### If it's not detected as a URL
                            prediction = model.predict([text])[0]
                            if prediction == 1:
                                link_classified(Text_input)
                            else:
                                text_classified(Text_input)
                    except Exception as e:
                        st.error("Error...\n\n",e,icon="⚠️")

                with st.spinner("Generating Article..."):
                    if __name__=="__main__":
                        model = train_model()
                        classify_input(Text_input, model)



####################################################################################################


#################################      Text summarizer
                 
        
if Main_menu == "Text Summarizer":
    
    blank_text_sum1, text_summarizer_col, blank_text_sum2 = st.columns([2,8,2],gap="small")

    ### blank columns
    with blank_text_sum1:
        pass
    with blank_text_sum2:
        pass

    ### text summarizer app column

    with text_summarizer_col:
        #### app title
        st.text("")
        text_summarizer_Title = colored_header(
            label="Text Summarizer 📄",
            color_name="violet-70",
            description="enter or paste text hear"
        )

        placeholder_text = """write or paste your text hear 
paragraph length should be greater then 30 words
to generate output tap on screen or press ctrl+enter
        """

        ### input box
        text_summarizer_input = st.text_area(
            label="Enter Text Hear",
            placeholder=placeholder_text,
            height=340,
            key="text summarizer"
        )
        Modal_Level(Summarizer_modal) 
        
        if text_summarizer_input.strip() == "":

            try:
                #### writing animation
                write_hear_animation  = insert_lottie_animation("lottie_animations/write-hear.json")
                st_lottie(
                    animation_source=write_hear_animation,
                    speed=1,
                    reverse=False,loop=True,
                    quality="medium",
                    height=165,
                    width=240,
                    key="write hear"
                )
            except Exception as err:
                st.warning("something went wrong...",err,icon="⚠️")

        ### enter paragraph length greater than 35 words
        elif len(text_summarizer_input.split()) < 20:
            st.warning("paragraph should be greater than 35 words",icon="✏️")   
                 
        else:
            
            def word_token_maxvalue(text:str)->int:
                """
                converting paragraph into
                tokens
                """
                word_para = []
                words = word_tokenize(text)
                for i in words:
                    word_para.append(i)

                return len(word_para)
            
            @st.cache_data
            def random_value_text(text:str)->int:
                random_value = np.random.randint(
                    10,word_token_maxvalue(text),6
                )
                
                return random.choice(random_value)
            
            def clean_data_for_summarization(text:str)->str:
                clean_text = clean(
                        text=text,fix_unicode=True,
                        to_ascii=True,no_emoji=True,
                        lang="en",no_line_breaks=False,
                        keep_two_line_breaks=True
                    )
                return clean_text

        

            text_Max_length = st.slider(
                label="Max length",
                min_value=10,
                max_value=word_token_maxvalue(text_summarizer_input),
                key="text summarizer max length",
                step=1,value=random_value_text(text_summarizer_input)
            )

            Generate_text_summary = st.button(
                label="Generate summary",key="text summary"
            )

            try:
                #### writing loading
                writing_loading_animation  = insert_lottie_animation("lottie_animations/writing-loading.json")
                summary_generating_animation = st_lottie_spinner(
                    animation_source=writing_loading_animation,
                    speed=2,
                    reverse=False,loop=True,
                    quality="medium",
                    height=165,
                    width=240,
                    key="writing generating"
                )
            except Exception as err:
                st.warning("something went wrong...",err,icon="⚠️")


            #### initilization of modal
            if Generate_text_summary:

                if __name__=="__main__":
                    
                    ##### summary generation
                    with summary_generating_animation:

                        ### modal
                        Text_Summary_output = Hugingface_summarization_modal(
                            summary_text=clean_data_for_summarization(text_summarizer_input),
                            modal_name=Summarizer_modal,
                            maximum_length=text_Max_length
                        )

                        ##### summary displaying and copy
                        st.text("")
                        st.text("")
                        st.markdown("<h4>Generated Summary</h4>",unsafe_allow_html=True)
                        st.text("")
                        st.write(Text_Summary_output)
                        st.text("")
                        
                        copy_text(Text_Summary_output)
                        st.text("")
                        st.text("")

                        ###### original text desplay and copy
                        st.markdown("<h4>Original Text</h4>",unsafe_allow_html=True)
                        st.text("")
                        original_text = clean_data_for_summarization(text_summarizer_input)
                        st.write(original_text)
                        st.text("")
                        copy_text(original_text)

                        st.text("")
                        st.text("")
                        st.text("")

                         ### summarization details
                        text_summarization_details = {
                            "Summarization Details":["Modal Name","Text Length","Summary Length","Max Tokens"],
                            "Output":[
                                f"{Summarizer_modal}",
                                f"Length - {len(text_summarizer_input.split())}",
                                f"Length - {len(Text_Summary_output.split())}",
                                f"Tokens Used - {text_Max_length}"
                            ]
                        }

                        summarization_details_df = pd.DataFrame(
                            data=text_summarization_details,
                            index=["Hugingface Modal","No. words","No. Words","Max Length"]
                        )

                        st.text("")
                        st.text("")
                        st.text("")
                        st.dataframe(summarization_details_df,use_container_width=True)
                        st.text("")
                        st.text("")
                        st.text("")
                        st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)



##############################################################################################################

##############################      pdf summarizer


#### pdf and text summarizer functions


#### displaying uploaded pdf file
def display_pdf_file(uploaded_file):
    """
    it is used to display the
    file on screen
    """
    #### saving the uploaded file
    def save_uploadfile(save_file):
        with open(os.path.join("data",save_file.name),"wb") as f:
            f.write(save_file.getbuffer())
            return st.toast("file uploaded: {}".format(save_file.name))
        
    try:
        ### display pdf on screen
        def displayPDF(pdf_file):
            with open(pdf_file,"rb") as f:
                base64_pdf = base64.b64encode(f.read()).decode("utf-8")

            pdf_display = f"""
                <iframe
                    src="data:application/pdf;base64,{base64_pdf}"
                    width="580" height="700"
                    type="application/pdf"
                >
                </iframe>
            """

            st.markdown(pdf_display,unsafe_allow_html=True)

        ### save and display file
        save_uploadfile(uploaded_file)
        pdf_file = "data/"+uploaded_file.name
        displayPDF(pdf_file)
    except Exception as e:
        st.warning("Something Went wrong...\n\n",e,icon="⚠️")


#### Function to extract text from a specific page using pdfminer
def extract_text_pdfminer(pdf_file, page_number):
    """
    this function extract pdf file
    text by user input page number
    """
    try:
        extracted_text = ''
        for i, page_layout in enumerate(extract_pages(pdf_file)):
            if i == page_number - 1:  
                ### Extract text elements and format them as closely as possible to the original layout
                for element in page_layout:
                    if isinstance(element, LTTextContainer):
                        for text_line in element:
                            if isinstance(text_line, LTTextLine):
                                line = ''.join([char.get_text() for char in text_line if isinstance(char, LTChar)])
                                extracted_text += line.strip() + '\n'
                return extracted_text
        return st.warning("Invalid page number.",icon="⚠️")
    except Exception as e:
        st.warning("Something Went wrong...\n\n",e,icon="⚠️")


###############################################


##### clean text for summmarization task
def uploaded_Clean_Text_Summarization(clean_text:str)->str:
        """
        it gives clean text for
        summarization task
        """
        try:
            pattern = r'[|`~^$<>]'
            cleaned_paragraph = re.sub(pattern, '', clean_text)

            ### using clean function
            clean_output_para = clean(
                text=cleaned_paragraph,fix_unicode=True,
                to_ascii=True,no_emoji=True,
                lang="en",no_line_breaks=False,
                keep_two_line_breaks=True
            )

        except Exception as e:
            st.warning("Something Went wrong...\n\n",e,icon="⚠️")

        return clean_output_para


### convert paragraph into tokens
def generate_text_para_tokens(text_para:str)->int:
    """
    converting paragraph into
    tokens
    """
    try:
        pattern = r'[|`~#^$<>]'
        cleaned_paragraph = re.sub(pattern, '', text_para)

            #### using clean function
        clean_para = clean(
            text=cleaned_paragraph,fix_unicode=True,
            to_ascii=True,no_emoji=True,
            lang="en",no_line_breaks=False,
            keep_two_line_breaks=True
        )

        word_tokens = []

        for i in word_tokenize(clean_para):
            word_tokens.append(i)
        return len(np.array(word_tokens))
    
    except Exception as e:
        st.warning("Something Went wrong...\n\n",e,icon="⚠️")



    ### generates random value for slider
@st.cache_data
def random_text_para_value(para:str)->int:
    try:
        random_value = np.random.randint(
            20, generate_text_para_tokens(para), 6
        )
        return random.choice(random_value)
    except Exception as e:
        st.warning("Something Went wrong...\n\n",e,icon="⚠️")


####  PDF files summarizer
def process_pdf(file):
    reader = PdfReader(file)
    page_count = len(reader.pages)

    ### pdf display and information column
    pdf_display_tab, pdf_summarizer_tab = st.tabs([f"Displaying {file.name}","Pdf Summarizer"])

    ####### displaying pdf on pdf display tab
    with pdf_display_tab:
        st.markdown(f"<h4>Pdf - {file.name}</h4>",unsafe_allow_html=True)

        pdf_col, pdf_info_col = st.columns([5,3],gap="medium")
        with pdf_col:
            with st.spinner("Displaying file..."):
                if __name__=="__main__":
                    display_pdf_file(file)

        with pdf_info_col:
            st.write("Your File: {}".format(file.name))
            st.write(f"Number of pages: {str(page_count)}")
            st.markdown(insert_html("htmlfiles/pdf-summarizer-info.html"),unsafe_allow_html=True)

           
    ### pdf information and intract with pdf
    with pdf_summarizer_tab:

        st.text("")
        st.markdown("<h4>Extract pdf text</h4>",unsafe_allow_html=True)

        ### toggle button for extracting text
        extract_by_page_all = st.toggle(
            label="Extract whole Text",key="toggle for extract text",
            value=False
        )

        ### extracting all pdf text
        if extract_by_page_all:
            st.write("Extract whole pdf Text")

            if st.button("Extract Whole Pdf",key="whole pdf text extract"):
            
                st.text("")
                st.text("")

                with st.spinner("Extracting pdf..."):
                    whole_pdf_text = extract_text(file)
                    st.markdown("<h4 style='font-size: 26px'>Whole PDF Text</h4>",unsafe_allow_html=True)
                    st.text("")
                    st.write(whole_pdf_text)
        else:
            reader = PdfReader(file)
            total_pages = len(reader.pages)
            st.write("Extract by page Number")

            pdf_page_no_col, pdf_page_noinfo_col = st.columns([3,5],gap="small")

            with pdf_page_no_col:

                ### input page number
                Pdf_page_number_input = st.number_input(
                    label="Select the page number",
                    min_value=1, max_value=total_pages,
                    value=1,key="pdf page number",step=1
                )

            with pdf_page_noinfo_col:
                st.text("")
                st.text("")
                st.write(f"Selected page: {str(Pdf_page_number_input)}")

            Extract_page_no_button = st.button(
                label="Extract Page text",
                key="Extract button for page"
            )
            st.text("")
            st.text("")

            if Extract_page_no_button:
                text_pdfminer = extract_text_pdfminer(file, Pdf_page_number_input)
                st.session_state['extracted_text'] = text_pdfminer  ### Store the extracted text in session state
            
            if 'extracted_text' in st.session_state:
                Pdf_file_text = st.text_area(
                    label=f"Text data of {Pdf_page_number_input} page",
                    value= st.session_state['extracted_text'], 
                    height=400
                )
                st.session_state['extracted_text'] = Pdf_file_text  # Update the text in session state based on user's input

                #### pdf summarizer
                st.text("")
                Max_length_pdf_slider = st.slider(
                    label="Max Length",key="Pdf summarizer slider",
                    min_value=10,max_value=generate_text_para_tokens(Pdf_file_text),
                    value=random_text_para_value(Pdf_file_text)
                )
                st.text("")

                upload_Pdf_summary_btn_col, upload_Pdf_print_btn_col, upload_clean_Pdf_print_btn_col, blank_Pdf_col1, blank_Pdf_col2 = st.columns(
                    [4,4,4,7,3],gap="small"
                )

                with blank_Pdf_col1:
                    pass
                with blank_Pdf_col2:
                    pass

                with upload_Pdf_summary_btn_col:
                    Generate_upload_pdf_summary_btn = st.button(
                        label="Generate Summary",
                        key="Generate summary of uploaded text pdf"
                    )

                with upload_clean_Pdf_print_btn_col:
                    Upload_clean_pdf_btn = st.button(
                        label="Print Clean Text",
                        key="Print clean pdf file"
                    )


                with upload_Pdf_print_btn_col:
                    upload_pdf_print_button = st.button(
                        label="Print Uploaded Text",
                        key="Print uploadded pdf"
                    )
                
                ### clean text
                if Upload_clean_pdf_btn:
                    with st.spinner("Generating Clean Text..."):
                        st.text("")
                        st.text("")
                        st.markdown("<h4 style='font-size: 26px'>Clean Text</h4>",unsafe_allow_html=True)
                        st.text("")
                        st.write(uploaded_Clean_Text_Summarization(Pdf_file_text))
                        st.text("")
                        copy_text(uploaded_Clean_Text_Summarization(Pdf_file_text))
                        st.text("")
                        st.text("")
                        st.text("")
                        st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)

                ### uploaded text
                elif upload_pdf_print_button:
                    with st.spinner("Generating Uploaded Text..."):
                        st.text("")
                        st.text("")
                        st.markdown("<h4 style='font-size: 26px'>Uploaded Text</h4>",unsafe_allow_html=True)
                        st.text("")
                        st.text(Pdf_file_text)
                        st.text("")
                        copy_text(Pdf_file_text)
                        st.text("")
                        st.text("")
                        st.text("")
                        st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)

                ### generating summary
                elif Generate_upload_pdf_summary_btn:
                    st.text("")
                    with st.spinner("Generating Summary..."):
                        st.text("")
                        if __name__=="__main__":
                            Uploded_Pdf_file_Summary = Hugingface_summarization_modal(
                                summary_text=uploaded_Clean_Text_Summarization(Pdf_file_text),
                                maximum_length=Max_length_pdf_slider,
                                modal_name="facebook-bart"
                            )
                            st.markdown("<h4 style='font-size: 26px'>Summary</h4>",unsafe_allow_html=True)
                            st.text("")

                            st.write(Uploded_Pdf_file_Summary)
                            st.text("")
                            copy_text(Uploded_Pdf_file_Summary)
                            st.text("")
                            st.text("")
                            st.text("")
                            st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)


                
                
#################################################


##### text file summarizer
def process_text(file):
    text_file = file.read().decode("utf-8")
    st.text("")
    st.markdown("<h4 style='font-size: 26px'>Text file</h4>",unsafe_allow_html=True)    

    
    ### displaying text you can edit also
    Uploaded_text = st.text_area(
        label=f"{file.name[:-4]} text data",
        value=text_file,key="text file data",
        height=400
    )
    st.write(f"**{file.name[:-4]}** Edit your file press ctrl+enter")

    ###3 if length is less than 20
    if len(Uploaded_text.split()) < 20:
        st.warning("Summarization Task failed\nnot enough amount of text...",icon="⚠️")

    else:
        st.text("")
        #### max length slider
        max_text_para_length = st.slider(
            label="Max Length",min_value=10,
            max_value=generate_text_para_tokens(Uploaded_text),
            step=1,key="paragraph length",
            value=random_text_para_value(Uploaded_text)
        )
        st.text("")
        
        upload_text_summary_btn_col, upload_text_print_btn_col, upload_clean_text_print_btn_col, blank_text_col1, blank_text_col2 = st.columns(
            [4,4,4,7,3],gap="small"
        )

        with blank_text_col1:
            pass
        with blank_text_col2:
            pass

        with upload_text_summary_btn_col:
            Generate_upload_text_summary_btn = st.button(
                label="Generate Summary",
                key="Generate summary of uploaded text"
            )

        with upload_clean_text_print_btn_col:
            Upload_clean_text_btn = st.button(
                label="Print Clean Text",
                key="Print clean text file"
            )


        with upload_text_print_btn_col:
            upload_text_print_button = st.button(
                label="Print Uploaded Text",
                key="Print uploadded text"
            )
        
        ### clean text
        if Upload_clean_text_btn:
            with st.spinner("Generating Clean Text..."):
                st.text("")
                st.text("")
                st.markdown("<h4 style='font-size: 26px'>Clean Text</h4>",unsafe_allow_html=True)
                st.text("")
                st.write(uploaded_Clean_Text_Summarization(Uploaded_text))
                st.text("")
                copy_text(uploaded_Clean_Text_Summarization(Uploaded_text))
                st.text("")
                st.text("")
                st.text("")
                st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",
                            unsafe_allow_html=True)

        ### uploaded text
        elif upload_text_print_button:
            with st.spinner("Generating Uploaded Text..."):
                st.text("")
                st.text("")
                st.markdown("<h4 style='font-size: 26px'>Uploaded Text</h4>",unsafe_allow_html=True)
                st.text("")
                st.text(Uploaded_text)
                st.text("")
                copy_text(Uploaded_text)
                st.text("")
                st.text("")
                st.text("")
                st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",
                            unsafe_allow_html=True)


        ### generating summary
        elif Generate_upload_text_summary_btn:
            st.text("")
            with st.spinner("Generating Summary..."):
                st.text("")
                if __name__=="__main__":
                    Uploded_Text_file_Summary = Hugingface_summarization_modal(
                        summary_text=uploaded_Clean_Text_Summarization(Uploaded_text),
                        maximum_length=max_text_para_length,
                        modal_name="facebook-bart"
                    )
                    st.markdown("<h4 style='font-size: 26px'>Summary</h4>",unsafe_allow_html=True)
                    st.text("")

                    st.write(Uploded_Text_file_Summary)
                    st.text("")
                    copy_text(Uploded_Text_file_Summary)
                    st.text("")
                    st.text("")
                    st.text("")
                    st.markdown("<h6 style='text-align: center;'>Created by Nishant Maity</h6>",unsafe_allow_html=True)



if Main_menu == "PDF Summarizer":
    
    ### blank and app columns
    Blank_pdf1 ,pdf_summarizer_col, Blank_pdf2 = st.columns([1,8,1],gap="small") 

    with Blank_pdf1:
        pass
    with Blank_pdf2:
        pass

    with pdf_summarizer_col:
        st.text("")
        st.header("PDF Summarizer")   ### app heading

        ### File uploader function
        app_file_upload = st.file_uploader("Upload a PDF or Text file", type=["pdf", "txt"])

        if app_file_upload is not None:
            
            ### if pdf file
            if app_file_upload.type == "application/pdf":
                if __name__=="__main__":
                    process_pdf(app_file_upload)

            #### if text file
            elif app_file_upload.type == "text/plain":
                if __name__=="__main__":
                    process_text(app_file_upload)
        
        else:
            st.info("Upload your pdf, text file")
            

 #### app info           
if Main_menu == "App Info":
    Blank_app_info1, App_info_col, Blank_app_info2 = st.columns([2,8,2])

    #### blank columns
    with Blank_app_info1:
        pass
    with Blank_app_info2:
        pass

    ### app info column
    with App_info_col:
        st.text("")
        st.header("App Info")
        st.text("")

        if __name__=="__main__":
            st.markdown(insert_html("htmlfiles/app-info.html"),
                unsafe_allow_html=True
            )