Mpavan45 commited on
Commit
1ea9964
·
verified ·
1 Parent(s): bebfb20

Update Intro.py

Browse files
Files changed (1) hide show
  1. Intro.py +51 -0
Intro.py CHANGED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from textblob import TextBlob
3
+ import spacy
4
+ from collections import Counter
5
+
6
+ # Load Spacy model
7
+ nlp = spacy.load("en_core_web_sm")
8
+
9
+ # App title
10
+ st.title("NLP Blog with Sidebar and Buttons")
11
+
12
+ # Sidebar options
13
+ st.sidebar.title("Select NLP Task")
14
+ task = st.sidebar.selectbox("Choose a task:", ["Sentiment Analysis", "Keyword Extraction", "Named Entity Recognition (NER)"])
15
+
16
+ # Input text area
17
+ st.write("Enter text for analysis below:")
18
+ user_text = st.text_area("Input your text here:", height=200)
19
+
20
+ # Buttons
21
+ if st.button("Analyze"):
22
+ if user_text.strip():
23
+ if task == "Sentiment Analysis":
24
+ # Perform sentiment analysis
25
+ blob = TextBlob(user_text)
26
+ sentiment = blob.sentiment
27
+ st.subheader("Sentiment Analysis Result")
28
+ st.write(f"Polarity: {sentiment.polarity:.2f}")
29
+ st.write(f"Subjectivity: {sentiment.subjectivity:.2f}")
30
+
31
+ elif task == "Keyword Extraction":
32
+ # Extract keywords
33
+ doc = nlp(user_text)
34
+ keywords = [token.text for token in doc if token.is_alpha and not token.is_stop]
35
+ most_common_keywords = Counter(keywords).most_common(10)
36
+ st.subheader("Keyword Extraction Result")
37
+ st.write("Most Common Keywords:")
38
+ st.write(most_common_keywords)
39
+
40
+ elif task == "Named Entity Recognition (NER)":
41
+ # Perform Named Entity Recognition
42
+ doc = nlp(user_text)
43
+ st.subheader("Named Entity Recognition Result")
44
+ for ent in doc.ents:
45
+ st.write(f"Entity: {ent.text}, Label: {ent.label_}")
46
+ else:
47
+ st.error("Please enter some text for analysis.")
48
+
49
+ # Footer
50
+ st.sidebar.write("---")
51
+ st.sidebar.write("Developed with ❤️ using Streamlit.")