awacke1 commited on
Commit
99747ef
Β·
1 Parent(s): c2d459d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py CHANGED
@@ -1,6 +1,15 @@
 
1
  import streamlit as st
2
  import re
3
  import json
 
 
 
 
 
 
 
 
4
 
5
  def remove_timestamps(text):
6
  return re.sub(r'\d{1,2}:\d{2}\n', '', text)
@@ -41,6 +50,40 @@ def unit_test(input_text):
41
  test_jsonl_list = create_jsonl_list(test_text_without_timestamps)
42
  st.write(test_jsonl_list)
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  text_input = st.text_area("Enter text:", value="", height=300)
45
  text_without_timestamps = remove_timestamps(text_input)
46
 
@@ -127,3 +170,17 @@ learning works this is model free reinforcement learning the reinforcement learn
127
 
128
  unit_test(unit_test_text_2)
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
  import streamlit as st
3
  import re
4
  import json
5
+ import nltk
6
+ from nltk.corpus import stopwords
7
+ from nltk import FreqDist
8
+ from graphviz import Digraph
9
+ from collections import Counter
10
+
11
+ nltk.download('punkt')
12
+ nltk.download('stopwords')
13
 
14
  def remove_timestamps(text):
15
  return re.sub(r'\d{1,2}:\d{2}\n', '', text)
 
50
  test_jsonl_list = create_jsonl_list(test_text_without_timestamps)
51
  st.write(test_jsonl_list)
52
 
53
+
54
+
55
+ def extract_high_information_words(text, top_n=10):
56
+ words = nltk.word_tokenize(text)
57
+ words = [word.lower() for word in words if word.isalpha()]
58
+
59
+ stop_words = set(stopwords.words('english'))
60
+ filtered_words = [word for word in words if word not in stop_words]
61
+
62
+ freq_dist = FreqDist(filtered_words)
63
+ high_information_words = [word for word, _ in freq_dist.most_common(top_n)]
64
+
65
+ return high_information_words
66
+
67
+
68
+ def create_relationship_graph(words):
69
+ graph = Digraph()
70
+
71
+ for index, word in enumerate(words):
72
+ graph.node(str(index), word)
73
+
74
+ if index > 0:
75
+ graph.edge(str(index - 1), str(index), label=str(index))
76
+
77
+ return graph
78
+
79
+
80
+ def display_relationship_graph(words):
81
+ graph = create_relationship_graph(words)
82
+ st.graphviz_chart(graph)
83
+
84
+
85
+
86
+
87
  text_input = st.text_area("Enter text:", value="", height=300)
88
  text_without_timestamps = remove_timestamps(text_input)
89
 
 
170
 
171
  unit_test(unit_test_text_2)
172
 
173
+
174
+
175
+
176
+
177
+ # Adding new functionality to the existing code
178
+ text_without_timestamps = remove_timestamps(unit_test_text_2)
179
+ top_words = extract_high_information_words(text_without_timestamps, 10)
180
+ st.markdown("**Top 10 High Information Words:**")
181
+ st.write(top_words)
182
+
183
+ st.markdown("**Relationship Graph:**")
184
+ display_relationship_graph(top_words)
185
+
186
+