-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
258 lines (208 loc) · 8.64 KB
/
app.py
File metadata and controls
258 lines (208 loc) · 8.64 KB
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
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
"""
NLP Virtual Assistant - Main Application
A comprehensive NLP tool with multiple capabilities built with Streamlit
"""
import streamlit as st
import nltk
nltk.download('all')
from datetime import datetime
from text_classifier import create_text_classification_interface
from text_generator import create_text_generation_interface
from summarizer import create_text_summarization_interface
from sentiment_analyzer import create_sentiment_analysis_interface
from translator import create_translation_interface
from question_answerer import create_question_answering_interface
from ner_extractor import create_ner_interface
def main():
"""
Main application function
"""
st.set_page_config(
page_title="NLP Virtual Assistant",
page_icon="🤖",
layout="wide",
initial_sidebar_state="expanded"
)
with st.sidebar:
st.markdown("### 🤖 NLP Virtual Assistant")
st.markdown("*Your AI-Powered Text Analysis Toolkit*")
st.markdown("---")
selected_tool = st.selectbox(
"Choose NLP Tool:",
[
"🏠 Home",
"📝 Text Classification",
"✍️ Text Generation",
"📄 Text Summarization",
"😊 Sentiment Analysis",
"🌍 Language Translation",
"❓ Question Answering",
"🏷️ Named Entity Recognition"
]
)
st.markdown("---")
with st.expander("ℹ️ About"):
st.write("""
**NLP Virtual Assistant** is a comprehensive tool that provides:
- **Text Classification**: Categorize text content
- **Text Generation**: Create stories, emails, blogs
- **Summarization**: Extract key information
- **Sentiment Analysis**: Analyze emotional tone
- **Translation**: Multi-language support
- **Question Answering**: Get answers from context
- **NER**: Extract entities from text
""")
if hasattr(st.session_state, 'usage_stats'):
with st.expander("📊 Usage Statistics"):
stats = st.session_state.usage_stats
for tool, count in stats.items():
st.metric(tool, count)
if selected_tool == "🏠 Home":
show_home_page()
elif selected_tool == "📝 Text Classification":
track_usage("Text Classification")
create_text_classification_interface()
elif selected_tool == "✍️ Text Generation":
track_usage("Text Generation")
create_text_generation_interface()
elif selected_tool == "📄 Text Summarization":
track_usage("Text Summarization")
create_text_summarization_interface()
elif selected_tool == "😊 Sentiment Analysis":
track_usage("Sentiment Analysis")
create_sentiment_analysis_interface()
elif selected_tool == "🌍 Language Translation":
track_usage("Language Translation")
create_translation_interface()
elif selected_tool == "❓ Question Answering":
track_usage("Question Answering")
create_question_answering_interface()
elif selected_tool == "🏷️ Named Entity Recognition":
track_usage("Named Entity Recognition")
create_ner_interface()
def show_home_page():
"""
Display the home page with overview and features
"""
st.markdown('<div class="main-header">', unsafe_allow_html=True)
st.title("🤖 NLP Virtual Assistant")
st.markdown("**Your Complete Natural Language Processing Toolkit**")
st.markdown('</div>', unsafe_allow_html=True)
st.markdown("---")
st.markdown("""
Welcome to the **NLP Virtual Assistant** - a powerful, all-in-one natural language processing tool
that helps you analyze, understand, and generate text content with ease.
""")
st.subheader("🚀 Available Features")
col1, col2 = st.columns(2)
with col1:
st.markdown("""
### 📝 **Text Classification**
Automatically categorize your text into different topics like technology, business, sports, health, and more.
### ✍️ **Text Generation**
Create engaging content including stories, professional emails, blog posts, and text continuations.
### 📄 **Text Summarization**
Extract key information from long documents with extractive summarization and bullet points.
### 😊 **Sentiment Analysis**
Analyze the emotional tone of text with detailed emotion detection and intensity analysis.
""")
with col2:
st.markdown("""
### 🌍 **Language Translation**
Translate text between multiple languages with automatic language detection.
### ❓ **Question Answering**
Get intelligent answers to questions based on provided context documents.
### 🏷️ **Named Entity Recognition**
Extract and identify people, organizations, locations, dates, and other entities from text.
### 🔧 **Batch Processing**
Process multiple texts or files at once for efficient workflow management.
""")
st.subheader("🎯 Quick Start Guide")
with st.expander("📖 How to Get Started"):
st.markdown("""
1. **Select a Tool**: Use the sidebar to choose the NLP feature you want to use
2. **Input Your Text**: Either type directly or upload a text file
3. **Configure Options**: Adjust settings based on your needs
4. **Get Results**: View comprehensive analysis and download results
5. **Try Different Tools**: Experiment with various NLP capabilities
### 💡 Tips for Best Results:
- Use clear, well-formatted text for better analysis
- For question answering, provide comprehensive context
- Try different summarization ratios to find the optimal length
- Use batch processing for multiple documents
""")
st.subheader("💼 Common Use Cases")
use_case_tabs = st.tabs(["📊 Business", "🎓 Education", "📰 Content", "🔬 Research"])
with use_case_tabs[0]:
st.markdown("""
**Business Applications:**
- Analyze customer feedback sentiment
- Classify support tickets automatically
- Generate professional email responses
- Summarize meeting notes and reports
- Translate content for global audiences
""")
with use_case_tabs[1]:
st.markdown("""
**Educational Use:**
- Summarize academic papers and articles
- Extract key concepts from textbooks
- Analyze essay sentiment and tone
- Generate study questions from content
- Translate educational materials
""")
with use_case_tabs[2]:
st.markdown("""
**Content Creation:**
- Generate blog post ideas and outlines
- Analyze content sentiment for audience targeting
- Create multilingual content versions
- Extract entities for SEO optimization
- Summarize competitor content
""")
with use_case_tabs[3]:
st.markdown("""
**Research Applications:**
- Extract entities from research papers
- Summarize literature reviews
- Classify research topics
- Analyze survey responses
- Generate research questions
""")
st.subheader("📢 System Information")
col1, col2, col3 = st.columns(3)
with col1:
st.info("**Status**: ✅ All systems operational")
with col2:
st.info(f"**Last Updated**: {datetime.now().strftime('%Y-%m-%d')}")
with col3:
st.info("**Version**: 1.0.0")
st.markdown("---")
st.markdown("""
<div style="text-align: center; color: #666; padding: 1rem;">
Built using Streamlit | Powered by Advanced NLP Libraries
</div>
""", unsafe_allow_html=True)
def track_usage(tool_name):
"""
Track usage statistics for analytics
"""
if 'usage_stats' not in st.session_state:
st.session_state.usage_stats = {}
if tool_name not in st.session_state.usage_stats:
st.session_state.usage_stats[tool_name] = 0
st.session_state.usage_stats[tool_name] += 1
def show_error_page(error_message):
"""
Display error page when something goes wrong
"""
st.error("🚨 Application Error")
st.write(f"An error occurred: {error_message}")
st.write("Please try refreshing the page or contact support if the issue persists.")
if st.button("🔄 Refresh Page"):
st.rerun()
if __name__ == "__main__":
try:
main()
except Exception as e:
show_error_page(str(e))