Mpavan45 commited on
Commit
947c2fc
·
verified ·
1 Parent(s): 103aa8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -45
app.py CHANGED
@@ -1,52 +1,55 @@
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.")
52
-
 
1
  import streamlit as st
 
 
 
 
 
 
2
 
3
  # App title
4
+ st.title("NLP Theory Blog")
5
+
6
+ # Sidebar for navigation
7
+ st.sidebar.title("Navigation")
8
+ pages = ["Introduction to NLP", "NLP Techniques"]
9
+ page = st.sidebar.radio("Go to:", pages)
10
+
11
+ # Content for each page
12
+ if page == "Introduction to NLP":
13
+ st.header("What is Natural Language Processing (NLP)?")
14
+ st.write("""
15
+ Natural Language Processing (NLP) is a field of Artificial Intelligence that focuses on the interaction between computers and humans through natural language.
16
+ It enables machines to understand, interpret, and respond to human language in a meaningful way.
17
+
18
+ **Applications of NLP include:**
19
+ - Sentiment Analysis
20
+ - Machine Translation
21
+ - Chatbots
22
+ - Speech Recognition
23
+
24
+ NLP combines computational linguistics with machine learning and deep learning techniques to process language.
25
+ """)
26
+
27
+ elif page == "NLP Techniques":
28
+ st.header("Common NLP Techniques")
29
+ st.write("""
30
+ NLP involves several techniques for processing and analyzing text and speech data. Here are some key techniques:
31
+
32
+ 1. **Tokenization:** Breaking text into smaller units like words or sentences.
33
+ 2. **Stopword Removal:** Eliminating common words (e.g., 'the', 'is') that may not contribute to meaning.
34
+ 3. **Stemming and Lemmatization:** Reducing words to their base or root form.
35
+ 4. **Part-of-Speech (POS) Tagging:** Identifying grammatical parts of speech in a text.
36
+ 5. **Named Entity Recognition (NER):** Extracting named entities like people, organizations, and locations.
37
+ 6. **Sentiment Analysis:** Determining the sentiment (positive, negative, neutral) of a text.
38
+ 7. **Text Summarization:** Producing a summary of a longer text.
39
+ 8. **Machine Translation:** Translating text from one language to another.
40
+
41
+ These techniques are often used in combination to build sophisticated NLP applications.
42
+ """)
43
+
44
+ # Pagination buttons
45
+ if st.button("Previous Page"):
46
+ if page == "NLP Techniques":
47
+ st.experimental_set_query_params(page=pages[0])
48
+
49
+ if st.button("Next Page"):
50
+ if page == "Introduction to NLP":
51
+ st.experimental_set_query_params(page=pages[1])
52
 
53
  # Footer
54
  st.sidebar.write("---")
55
  st.sidebar.write("Developed with ❤️ using Streamlit.")