systash's picture
Update app.py
fbf6aae
raw
history blame contribute delete
No virus
3.36 kB
import streamlit as st
import yake
import regex as re
import spacy
st.set_page_config(
page_title="Hashtag and Named Entity Generator",
page_icon='🔖',
layout="wide",
initial_sidebar_state="auto"
)
st.markdown('<link href="theme.css" rel="stylesheet">', unsafe_allow_html=True)
st.title('Hashtag and Named Entity Generator')
text = """Recently, Chat GPT a language chatbot was launched in November 2022 and is developed by Open AI. ChatGPT uses a GPT 3.5 technology which generates conversations that resemble those made by humans in their lives. This was done with the help of deep learning which contributed immensely to its creation.
It can write e-mails for users or write an essay. It has become an Internet phenomenon just in a couple of months. Many found this to be cool automation useful for many.
Recently, various companies in the United States of America have curbed the use of Chat GPT as they fear its misuse of it. Verizon Communications had earlier banned the use of AI because they feared that they could lose ownership of customer information if typed into Chat GPT.
The giant in the world of investment banking, JP Morgan Chase and Co. have also restricted its employees from using the chatbot, ChatGPT at work. However, the financial giant declined to comment on its policy on staffers using ChatGPT at the workplace when asked by Reuters. Their motive behind this restriction is speculated by many.
Interestingly, Chat GPT has become so popular by now that big brands such as Google launched Bard which is their AI conversational service. Whereas, on the other hand, Microsoft launched Bing. It is an AI-integrated search engine by Microsoft.
Chat GPT has received criticism as well as appreciation both so far. However, an important question that often arises is – Will such AI replace jobs done by humans? Well, the future is yet to come and there are mysteries that are yet to unravel. So, if you wonder about this, you will find out soon."""
nlp = spacy.load("en_core_web_sm")
cola, colb = st.columns(2)
with cola:
input_text = st.text_area(label="", value=text, placeholder="Enter your text here", height=10)
button_clicked = st.button("Generate Hashtags and Entities")
if input_text or button_clicked:
kw_extractor = yake.KeywordExtractor()
keywords = kw_extractor.extract_keywords(input_text)
entities = nlp(input_text)
phrases = []
for i in range(len(keywords)):
phrase = keywords[i][0]
for j in range(i + 1, len(keywords)):
if keywords[j][1] == keywords[i][1]:
phrase += keywords[j][0]
else:
break
phrases.append(phrase)
hashtags = []
for phrase in phrases:
hashtag = "#" + re.sub(r'\W+', '', phrase).lower()
hashtags.append(hashtag)
with cola:
with st.container():
with st.expander("Hashtags"):
st.write(", ".join(hashtags))
with st.expander("Named Entities"):
ent_list = []
for entity in entities.ents:
if "#" not in entity.text and entity.label_ in ["PERSON", "ORG"]:
ent_list.append(entity.text+" : "+entity.label_)
ent_set = set(ent_list)
ent_string = ', '.join(list(ent_set))
st.write(ent_string)