File size: 3,691 Bytes
50f868a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
import pandas as pd
import streamlit as st
from PIL import Image

padding_top = 0
st.markdown(f"""
    <style>
        .reportview-container .main .block-container{{
            padding-top: {padding_top}rem;
        }}
    </style>""",
    unsafe_allow_html=True,
)

def set_page_title(title):
    st.sidebar.markdown(unsafe_allow_html=True, body=f"""
        <iframe height=0 srcdoc="<script>
            const title = window.parent.document.querySelector('title') \
            const oldObserver = window.parent.titleObserver
            if (oldObserver) {{
                oldObserver.disconnect()
            }} \
            const newObserver = new MutationObserver(function(mutations) {{
                const target = mutations[0].target
                if (target.text !== '{title}') {{
                    target.text = '{title}'
                }}
            }}) \
            newObserver.observe(title, {{ childList: true }})
            window.parent.titleObserver = newObserver \
            title.text = '{title}'
        </script>" />
    """)


set_page_title('NLP use cases')

 #Hide Menu Option
hide_streamlit_style = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            </style>
            """
st.markdown(hide_streamlit_style, unsafe_allow_html=True)

Image.open('hf2.png').convert('RGB').save('hf2.png')
img = Image.open("hf2.png")


st.markdown("<h1 style='text-align: center; color: #3366ff;'>NLP Basic Use Cases</h1>", unsafe_allow_html=True)
st.markdown("---")
with st.sidebar:
    # title using markdown
    st.markdown("<h1 style='text-align: left; color: ;'>NLP Tasks</h1>", unsafe_allow_html=True)
    select_task=st.selectbox(label="Select task from drop down menu",
                 options=['README',
                          'Topic Modeling Using KeyPhrases',
                          'NER Extraction',
                          'POS Extraction'])

img = Image.open("hf2.png")

if select_task=='README':
    st.header("NLP Summary")
    st.write(f"The App gives you ability to 1) Detect Topics using Key-Phrase extraction technique")
    st.markdown("---")
    st.image(img)

from keybert import KeyBERT
from keyphrase_vectorizers import KeyphraseTfidfVectorizer,KeyphraseCountVectorizer

if select_task == 'Topic Modeling Using KeyPhrases':

    default_paratext = """ A molar tooth from Southeast Asia probably belonged to a member of a cryptic group of Stone Age hominids called Denisovans, researchers say.  If so, this relatively large tooth joins only a handful of fossils from Denisovans, who are known from ancient DNA pegging them as close Neandertal relatives.  Analyses of the tooth’s internal structure and protein makeup indicate that the molar came from a girl in the Homo genus. She died between the ages of 3½ and 8½, paleoanthropologist Fabrice Demeter of the University of Copenhagen and colleagues say."""

    input_texts = st.text_area(label="Input text to classify into topics",
                               height=250, max_chars=1000,
                               value=default_paratext)


    countVect=KeyphraseCountVectorizer()
    countVect.fit([input_texts])
    keyPhrases=countVect.get_feature_names_out()

    kb=KeyBERT()
    final=kb.extract_keywords([input_texts],vectorizer=KeyphraseCountVectorizer())
    st.subheader("Topics using Count Vectorizer")
    st.dataframe(pd.DataFrame(final,columns=['Topic','Score']))

    kb = KeyBERT()
    final2 = kb.extract_keywords([input_texts], vectorizer=KeyphraseTfidfVectorizer())
    st.subheader("Topics using Tf-IDF Vectorizer")
    st.dataframe(pd.DataFrame(final2, columns=['Topic', 'Score']))