Spaces:
Build error
Build error
Commit
•
50f868a
1
Parent(s):
d468b57
push all
Browse files- .streamlit/config.toml +34 -0
- app.py +95 -0
- hf2.png +0 -0
- requirements.txt +4 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
#theme primary
|
3 |
+
base="light"
|
4 |
+
# Primary accent color for interactive elements.
|
5 |
+
#primaryColor =
|
6 |
+
|
7 |
+
# Background color for the main content area.
|
8 |
+
#backgroundColor =
|
9 |
+
|
10 |
+
# Background color used for the sidebar and most interactive widgets.
|
11 |
+
#secondaryBackgroundColor ='grey'
|
12 |
+
|
13 |
+
# Color used for almost all text.
|
14 |
+
#textColor ='blue'
|
15 |
+
|
16 |
+
# Font family for all text in the app, except code blocks. One of "sans serif", "serif", or "monospace".
|
17 |
+
# Default: "sans serif"
|
18 |
+
font = "sans serif"
|
19 |
+
|
20 |
+
# [logger]
|
21 |
+
# level='info'
|
22 |
+
# messageFormat = "%(message)s"
|
23 |
+
#messageFormat="%(asctime)s %(message)s"
|
24 |
+
|
25 |
+
[global]
|
26 |
+
|
27 |
+
# By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.
|
28 |
+
# If you'd like to turn off this warning, set this to True.
|
29 |
+
# Default: false
|
30 |
+
disableWatchdogWarning = false
|
31 |
+
|
32 |
+
# If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".
|
33 |
+
# Default: true
|
34 |
+
showWarningOnDirectExecution = false
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
padding_top = 0
|
6 |
+
st.markdown(f"""
|
7 |
+
<style>
|
8 |
+
.reportview-container .main .block-container{{
|
9 |
+
padding-top: {padding_top}rem;
|
10 |
+
}}
|
11 |
+
</style>""",
|
12 |
+
unsafe_allow_html=True,
|
13 |
+
)
|
14 |
+
|
15 |
+
def set_page_title(title):
|
16 |
+
st.sidebar.markdown(unsafe_allow_html=True, body=f"""
|
17 |
+
<iframe height=0 srcdoc="<script>
|
18 |
+
const title = window.parent.document.querySelector('title') \
|
19 |
+
const oldObserver = window.parent.titleObserver
|
20 |
+
if (oldObserver) {{
|
21 |
+
oldObserver.disconnect()
|
22 |
+
}} \
|
23 |
+
const newObserver = new MutationObserver(function(mutations) {{
|
24 |
+
const target = mutations[0].target
|
25 |
+
if (target.text !== '{title}') {{
|
26 |
+
target.text = '{title}'
|
27 |
+
}}
|
28 |
+
}}) \
|
29 |
+
newObserver.observe(title, {{ childList: true }})
|
30 |
+
window.parent.titleObserver = newObserver \
|
31 |
+
title.text = '{title}'
|
32 |
+
</script>" />
|
33 |
+
""")
|
34 |
+
|
35 |
+
|
36 |
+
set_page_title('NLP use cases')
|
37 |
+
|
38 |
+
#Hide Menu Option
|
39 |
+
hide_streamlit_style = """
|
40 |
+
<style>
|
41 |
+
#MainMenu {visibility: hidden;}
|
42 |
+
footer {visibility: hidden;}
|
43 |
+
</style>
|
44 |
+
"""
|
45 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
46 |
+
|
47 |
+
Image.open('hf2.png').convert('RGB').save('hf2.png')
|
48 |
+
img = Image.open("hf2.png")
|
49 |
+
|
50 |
+
|
51 |
+
st.markdown("<h1 style='text-align: center; color: #3366ff;'>NLP Basic Use Cases</h1>", unsafe_allow_html=True)
|
52 |
+
st.markdown("---")
|
53 |
+
with st.sidebar:
|
54 |
+
# title using markdown
|
55 |
+
st.markdown("<h1 style='text-align: left; color: ;'>NLP Tasks</h1>", unsafe_allow_html=True)
|
56 |
+
select_task=st.selectbox(label="Select task from drop down menu",
|
57 |
+
options=['README',
|
58 |
+
'Topic Modeling Using KeyPhrases',
|
59 |
+
'NER Extraction',
|
60 |
+
'POS Extraction'])
|
61 |
+
|
62 |
+
img = Image.open("hf2.png")
|
63 |
+
|
64 |
+
if select_task=='README':
|
65 |
+
st.header("NLP Summary")
|
66 |
+
st.write(f"The App gives you ability to 1) Detect Topics using Key-Phrase extraction technique")
|
67 |
+
st.markdown("---")
|
68 |
+
st.image(img)
|
69 |
+
|
70 |
+
from keybert import KeyBERT
|
71 |
+
from keyphrase_vectorizers import KeyphraseTfidfVectorizer,KeyphraseCountVectorizer
|
72 |
+
|
73 |
+
if select_task == 'Topic Modeling Using KeyPhrases':
|
74 |
+
|
75 |
+
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."""
|
76 |
+
|
77 |
+
input_texts = st.text_area(label="Input text to classify into topics",
|
78 |
+
height=250, max_chars=1000,
|
79 |
+
value=default_paratext)
|
80 |
+
|
81 |
+
|
82 |
+
countVect=KeyphraseCountVectorizer()
|
83 |
+
countVect.fit([input_texts])
|
84 |
+
keyPhrases=countVect.get_feature_names_out()
|
85 |
+
|
86 |
+
kb=KeyBERT()
|
87 |
+
final=kb.extract_keywords([input_texts],vectorizer=KeyphraseCountVectorizer())
|
88 |
+
st.subheader("Topics using Count Vectorizer")
|
89 |
+
st.dataframe(pd.DataFrame(final,columns=['Topic','Score']))
|
90 |
+
|
91 |
+
kb = KeyBERT()
|
92 |
+
final2 = kb.extract_keywords([input_texts], vectorizer=KeyphraseTfidfVectorizer())
|
93 |
+
st.subheader("Topics using Tf-IDF Vectorizer")
|
94 |
+
st.dataframe(pd.DataFrame(final2, columns=['Topic', 'Score']))
|
95 |
+
|
hf2.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Pillow~=9.2.0
|
2 |
+
keybert~=0.6.0
|
3 |
+
keyphrase-vectorizers
|
4 |
+
streamlit
|