HHansi commited on
Commit
e2cb08c
1 Parent(s): bf5e273

initial commit

Browse files
Files changed (2) hide show
  1. accord_logo.png +0 -0
  2. app.py +12 -14
accord_logo.png ADDED
app.py CHANGED
@@ -1,9 +1,12 @@
1
  # Created by Hansi at 30/08/2023
 
 
2
  import nltk
3
  nltk.download('punkt')
4
  nltk.download('averaged_perceptron_tagger')
5
 
6
  import streamlit as st
 
7
  from accord_nlp.information_extraction.convertor import entity_pairing, graph_building
8
  from accord_nlp.information_extraction.ie_pipeline import InformationExtractor
9
 
@@ -17,6 +20,7 @@ re_args = {
17
  "labels_list": ["selection", "necessity", "none", "greater", "part-of", "equal", "greater-equal", "less-equal", "not-part-of", "less"],
18
  "special_tags": ["<e1>", "<e2>"], # Should be either begin_tag or end_tag
19
  "use_multiprocessing": False,
 
20
  }
21
 
22
  @st.cache_resource
@@ -37,8 +41,12 @@ with st.spinner(text="Initialising..."):
37
 
38
 
39
  def main():
40
- st.sidebar.title("ACCORD-NLP")
41
- st.sidebar.markdown("Extract information from text")
 
 
 
 
42
  st.sidebar.markdown(
43
  "[code](https://github.com/Accord-Project/NLP-Framework)"
44
  )
@@ -47,39 +55,29 @@ def main():
47
 
48
  txt = st.text_area('Sentence')
49
 
50
- # st.write(txt)
51
-
52
- # with st.spinner(text="Processing..."):
53
- # graph = ie.sentence_to_graph(txt)
54
-
55
  if txt:
56
  # preprocess
57
  sentence = ie.preprocess(txt)
58
- st.write(sentence)
59
 
60
  # NER
61
  with st.spinner(text="Recognising entities..."):
62
  ner_predictions, ner_raw_outputs = ie.ner_model.predict([sentence])
63
 
64
- st.write(ner_predictions)
65
-
66
  with st.spinner(text="Extracting relations..."):
67
  # pair entities to predict their relations
68
  entity_pair_df = entity_pairing(sentence, ner_predictions[0])
69
- # st.write('entity paired')
70
 
71
  # relation extraction
72
  re_predictions, re_raw_outputs = ie.re_model.predict(entity_pair_df['output'].tolist())
73
  entity_pair_df['prediction'] = re_predictions
74
- # st.write(re_predictions)
75
 
76
  with st.spinner(text="Building graph..."):
77
  # build graph
78
  graph = graph_building(entity_pair_df, view=False)
79
- # st.success()
80
 
81
  st.header('Entity-Relation Representation')
82
- st.graphviz_chart(graph)
 
83
 
84
 
85
  if __name__ == '__main__':
 
1
  # Created by Hansi at 30/08/2023
2
+ import os
3
+
4
  import nltk
5
  nltk.download('punkt')
6
  nltk.download('averaged_perceptron_tagger')
7
 
8
  import streamlit as st
9
+ from PIL import Image
10
  from accord_nlp.information_extraction.convertor import entity_pairing, graph_building
11
  from accord_nlp.information_extraction.ie_pipeline import InformationExtractor
12
 
 
20
  "labels_list": ["selection", "necessity", "none", "greater", "part-of", "equal", "greater-equal", "less-equal", "not-part-of", "less"],
21
  "special_tags": ["<e1>", "<e2>"], # Should be either begin_tag or end_tag
22
  "use_multiprocessing": False,
23
+ "process_count": 1
24
  }
25
 
26
  @st.cache_resource
 
41
 
42
 
43
  def main():
44
+ image = Image.open(os.path.join(os.path.dirname(__file__), 'accord_logo.png'))
45
+ st.sidebar.image(image)
46
+
47
+ # st.sidebar.title("ACCORD-NLP")
48
+ st.sidebar.header("Information Extractor")
49
+ st.sidebar.markdown("Extract entities and their relations from textual data")
50
  st.sidebar.markdown(
51
  "[code](https://github.com/Accord-Project/NLP-Framework)"
52
  )
 
55
 
56
  txt = st.text_area('Sentence')
57
 
 
 
 
 
 
58
  if txt:
59
  # preprocess
60
  sentence = ie.preprocess(txt)
 
61
 
62
  # NER
63
  with st.spinner(text="Recognising entities..."):
64
  ner_predictions, ner_raw_outputs = ie.ner_model.predict([sentence])
65
 
 
 
66
  with st.spinner(text="Extracting relations..."):
67
  # pair entities to predict their relations
68
  entity_pair_df = entity_pairing(sentence, ner_predictions[0])
 
69
 
70
  # relation extraction
71
  re_predictions, re_raw_outputs = ie.re_model.predict(entity_pair_df['output'].tolist())
72
  entity_pair_df['prediction'] = re_predictions
 
73
 
74
  with st.spinner(text="Building graph..."):
75
  # build graph
76
  graph = graph_building(entity_pair_df, view=False)
 
77
 
78
  st.header('Entity-Relation Representation')
79
+ # st.graphviz_chart(graph)
80
+ st.graphviz_chart(graph, use_container_width=True)
81
 
82
 
83
  if __name__ == '__main__':