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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import nltk
|
| 3 |
+
from nltk.corpus import stopwords
|
| 4 |
+
from nltk.tokenize import word_tokenize
|
| 5 |
import streamlit as st
|
| 6 |
+
import base64
|
| 7 |
+
import string
|
| 8 |
+
from facts import show_fun_fact
|
| 9 |
|
| 10 |
+
# Download necessary resources
|
| 11 |
+
#nltk.download('punkt')
|
| 12 |
+
#nltk.download('stopwords')
|
| 13 |
+
|
| 14 |
+
# Set Streamlit page config
|
| 15 |
+
st.set_page_config(layout="centered")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Encode image for the title
|
| 19 |
+
def encode_image(image_path):
|
| 20 |
+
with open(image_path, "rb") as image_file:
|
| 21 |
+
return base64.b64encode(image_file.read()).decode()
|
| 22 |
+
|
| 23 |
+
def add_bg_from_local(image_file):
|
| 24 |
+
encoded_string = encode_image(image_file)
|
| 25 |
+
st.markdown(
|
| 26 |
+
f"""
|
| 27 |
+
<style>
|
| 28 |
+
.stApp {{
|
| 29 |
+
background-image: url(data:image/{"png"};base64,{encoded_string});
|
| 30 |
+
background-size: cover;
|
| 31 |
+
background-repeat: no-repeat;
|
| 32 |
+
background-attachment: fixed;
|
| 33 |
+
}}
|
| 34 |
+
</style>
|
| 35 |
+
""",
|
| 36 |
+
unsafe_allow_html=True
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Set the background image
|
| 40 |
+
add_bg_from_local("Images/backgroud.jpg")
|
| 41 |
+
|
| 42 |
+
file_ = open("Images/title-icon-unscreen.gif", "rb").read()
|
| 43 |
+
base64_gif = base64.b64encode(file_).decode("utf-8")
|
| 44 |
+
|
| 45 |
+
st.markdown(
|
| 46 |
+
f"""
|
| 47 |
+
<h1 style='text-align: center; color: white;'>
|
| 48 |
+
Natural Language Processing
|
| 49 |
+
<img src="data:image/gif;base64,{base64_gif}" alt="Icon" style="width: 85px; margin-right: 10px;">
|
| 50 |
+
</h1>
|
| 51 |
+
""",
|
| 52 |
+
unsafe_allow_html=True
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
title_image_base64 = encode_image(r"Images/NLP_title_img.jpg")
|
| 56 |
+
st.image("Images/NLP_title_img.jpg", caption="Unlocking the power of language with NLP", use_column_width=True)
|
| 57 |
+
|
| 58 |
+
# Introduction section with emojis and styled text
|
| 59 |
+
st.markdown("<h2 style='text-align: center; color: white;'>What You'll Discover Here π΅οΈββοΈ</h2>", unsafe_allow_html=True)
|
| 60 |
+
|
| 61 |
+
st.markdown("""
|
| 62 |
+
- π **Introduction to NLP**: Learn the fundamentals of how machines understand human language.
|
| 63 |
+
- π οΈ **Life Cycle of NLP Projects**: Understand the step-by-step process of building NLP solutions.
|
| 64 |
""")
|
| 65 |
|
| 66 |
+
st.markdown("<h2 style='text-align: center; color: white;'> Why NLP Matters? π</h2>", unsafe_allow_html=True)
|
| 67 |
+
st.markdown("""
|
| 68 |
+
From understanding human emotions to powering search engines, Natural Language Processing (NLP) is everywhere.
|
| 69 |
+
Some real-world applications include:
|
| 70 |
+
- Chatbots and virtual assistants (e.g., Siri, Alexa).
|
| 71 |
+
- Sentiment analysis in social media.
|
| 72 |
+
- Language translation (e.g., Google Translate).
|
| 73 |
+
- Text summarization for news and articles.
|
| 74 |
+
- Personalized recommendations.
|
| 75 |
""")
|
| 76 |
|
| 77 |
+
st.markdown("<h2 style='text-align: center; color: white;'> Try It Yourself! π§βπ¬</h2>", unsafe_allow_html=True)
|
| 78 |
+
user_input = st.text_area("Enter any text to see how it's processed:", "Natural Language Processing is amazing!")
|
| 79 |
+
|
| 80 |
+
if user_input:
|
| 81 |
+
# Tokenization
|
| 82 |
+
tokens = word_tokenize(user_input)
|
| 83 |
+
st.write("### Tokens:")
|
| 84 |
+
st.write(tokens)
|
| 85 |
+
|
| 86 |
+
# Stopword and punctuation removal
|
| 87 |
+
stop_words = set(stopwords.words("english"))
|
| 88 |
+
cleaned_tokens = [word for word in tokens if word.lower() not in stop_words and word not in string.punctuation]
|
| 89 |
|
| 90 |
+
st.write("### After Removing Stopwords and Punctuation:")
|
| 91 |
+
st.write(cleaned_tokens)
|
| 92 |
+
|
| 93 |
+
st.markdown("## Ready to Get Started with NLP? π")
|
| 94 |
+
st.markdown("""
|
| 95 |
+
Letβs get started and explore the exciting Introduction to NLP! π
|
| 96 |
""")
|
| 97 |
+
|
| 98 |
+
show_fun_fact()
|
| 99 |
+
|
| 100 |
+
# Credir Section
|
| 101 |
+
st.markdown("""
|
| 102 |
+
<style>
|
| 103 |
+
.footer {
|
| 104 |
+
width: 100%;
|
| 105 |
+
text-align: center;
|
| 106 |
+
color: white;
|
| 107 |
+
padding: 20px 0;
|
| 108 |
+
background: linear-gradient(135deg, #f36f6f, #FF7F50); /* Gradient background */
|
| 109 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); /* Adds shadow for a 3D effect */
|
| 110 |
+
margin-top: 50px;
|
| 111 |
+
border-radius: 10px 10px 0 0; /* Rounded corners */
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.footer p {
|
| 115 |
+
font-size: 18px;
|
| 116 |
+
font-weight: bold;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.footer a {
|
| 120 |
+
color: white;
|
| 121 |
+
text-decoration: none;
|
| 122 |
+
margin: 0 10px;
|
| 123 |
+
transition: transform 0.3s ease, scale 0.2s;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.footer a:hover {
|
| 127 |
+
transform: scale(1.2);
|
| 128 |
+
transition: transform 0.3s ease;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.footer img {
|
| 132 |
+
margin-left: 8px;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.footer a:active {
|
| 136 |
+
transform: scale(1);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.footer span {
|
| 140 |
+
font-size: 14px;
|
| 141 |
+
display: block;
|
| 142 |
+
margin-top: 8px;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.footer .icons {
|
| 146 |
+
margin-top: 15px;
|
| 147 |
+
}
|
| 148 |
+
</style>
|
| 149 |
+
|
| 150 |
+
<div class="footer">
|
| 151 |
+
<p>Created with π‘ by Aamer
|
| 152 |
+
<a href='https://linkedin.com/mohd-suhaib-aamer' target='_blank'>
|
| 153 |
+
<img src='https://img.icons8.com/fluent/48/000000/linkedin.png' width='24' height='24'/>
|
| 154 |
+
</a>
|
| 155 |
+
<a href='https://github.com/Suhaib-Aamer' target='_blank'>
|
| 156 |
+
<img src='https://img.icons8.com/fluent/48/000000/github.png' width='24' height='24'/>
|
| 157 |
+
</a>
|
| 158 |
+
</p>
|
| 159 |
+
<span>Thank you for exploring NLP with me!</span>
|
| 160 |
+
</div>
|
| 161 |
+
""", unsafe_allow_html=True)
|