fadzwan commited on
Commit
63fd708
1 Parent(s): 7a9577c

Update app.py

Browse files

NER for Boycott dataset

Files changed (1) hide show
  1. app.py +16 -28
app.py CHANGED
@@ -1,38 +1,26 @@
1
  import streamlit as st
2
- import spacy
3
- from spacy import displacy
4
- from collections import Counter
5
 
6
- # Load the English language model
7
- nlp = spacy.load("en_core_web_sm")
 
8
 
9
- def process_text(text):
10
- # Process the text using the spaCy pipeline
11
- doc = nlp(text)
12
-
13
- # Extract the named entities
14
- entities = [(ent.text, ent.label_) for ent in doc.ents]
15
-
16
- # Count the occurrences of each entity type
17
- entity_counts = Counter([ent[1] for ent in entities])
18
-
19
- # Visualize the named entities using displacy
20
- ent_html = displacy.render(doc, style="ent")
21
-
22
- return ent_html, dict(entity_counts)
23
 
24
  def main():
25
- st.set_page_config(page_title="Named Entity Extraction")
26
- st.title("Named Entity Extraction")
27
- st.write("This app uses spaCy to extract named entities from the given text and visualize them.")
28
 
29
- text = st.text_area("Text to Process", height=200, placeholder="Enter the text you want to analyze")
30
 
31
- if st.button("Process Text"):
32
- ent_html, entity_counts = process_text(text)
33
- st.markdown(ent_html, unsafe_allow_html=True)
34
- st.subheader("Entity Type Counts")
35
- st.dataframe(entity_counts, use_container_width=True)
36
 
37
  if __name__ == "__main__":
38
  main()
 
1
  import streamlit as st
2
+ import json
 
 
3
 
4
+ # Load the data from the JSON file
5
+ with open('data.json', 'r') as f:
6
+ data = json.load(f)
7
 
8
+ def display_brand_info(parent_company):
9
+ brand_info = ''
10
+ for brand_id, brand in data['brands'].items():
11
+ if parent_company.lower() in brand['description'].lower():
12
+ brand_info += f"# {brand['name']}\n{brand['description']}\n---\n"
13
+ return brand_info
 
 
 
 
 
 
 
 
14
 
15
  def main():
16
+ st.set_page_config(page_title="Brand Information")
17
+ st.title("Brand Information")
 
18
 
19
+ parent_company = st.text_input("Enter Parent Company")
20
 
21
+ if parent_company:
22
+ brand_info = display_brand_info(parent_company)
23
+ st.markdown(brand_info)
 
 
24
 
25
  if __name__ == "__main__":
26
  main()