Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import re
|
| 3 |
import nltk
|
|
@@ -6,6 +7,7 @@ from nltk.corpus import stopwords
|
|
| 6 |
from nltk import FreqDist
|
| 7 |
from graphviz import Digraph
|
| 8 |
|
|
|
|
| 9 |
nltk.download('punkt')
|
| 10 |
nltk.download('stopwords')
|
| 11 |
|
|
@@ -64,15 +66,17 @@ def display_context_table(context_words):
|
|
| 64 |
table += f"| {before if before else ''} | {high} | {after if after else ''} |\n"
|
| 65 |
st.markdown(table)
|
| 66 |
|
|
|
|
| 67 |
def load_example_files():
|
| 68 |
example_files = [f for f in os.listdir() if f.endswith('.txt')]
|
| 69 |
-
selected_file = st.selectbox("Select an example file:", example_files)
|
| 70 |
-
if st.button(f"Load {selected_file}"):
|
| 71 |
with open(selected_file, 'r', encoding="utf-8") as file:
|
| 72 |
return file.read()
|
| 73 |
return None
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
example_text = load_example_files()
|
| 78 |
|
|
@@ -85,17 +89,18 @@ else:
|
|
| 85 |
|
| 86 |
if file_text:
|
| 87 |
text_without_timestamps = remove_timestamps(file_text)
|
| 88 |
-
|
| 89 |
top_words = extract_high_information_words(text_without_timestamps, 10)
|
| 90 |
-
st.markdown("**Top 10 High Information Words:**")
|
| 91 |
-
st.write(top_words)
|
| 92 |
|
| 93 |
-
st.
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
context_words = extract_context_words(text_without_timestamps, top_words)
|
| 97 |
-
st.markdown("**Context Graph:**")
|
| 98 |
-
display_context_graph(context_words)
|
| 99 |
|
| 100 |
-
st.
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
import streamlit as st
|
| 3 |
import re
|
| 4 |
import nltk
|
|
|
|
| 7 |
from nltk import FreqDist
|
| 8 |
from graphviz import Digraph
|
| 9 |
|
| 10 |
+
# Download NLTK resources
|
| 11 |
nltk.download('punkt')
|
| 12 |
nltk.download('stopwords')
|
| 13 |
|
|
|
|
| 66 |
table += f"| {before if before else ''} | {high} | {after if after else ''} |\n"
|
| 67 |
st.markdown(table)
|
| 68 |
|
| 69 |
+
# Load example files
|
| 70 |
def load_example_files():
|
| 71 |
example_files = [f for f in os.listdir() if f.endswith('.txt')]
|
| 72 |
+
selected_file = st.selectbox("๐ Select an example file:", example_files)
|
| 73 |
+
if st.button(f"๐ Load {selected_file}"):
|
| 74 |
with open(selected_file, 'r', encoding="utf-8") as file:
|
| 75 |
return file.read()
|
| 76 |
return None
|
| 77 |
|
| 78 |
+
# Main code for UI
|
| 79 |
+
uploaded_file = st.file_uploader("๐ Choose a .txt file", type=['txt'])
|
| 80 |
|
| 81 |
example_text = load_example_files()
|
| 82 |
|
|
|
|
| 89 |
|
| 90 |
if file_text:
|
| 91 |
text_without_timestamps = remove_timestamps(file_text)
|
|
|
|
| 92 |
top_words = extract_high_information_words(text_without_timestamps, 10)
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
with st.expander("๐ Top 10 High Information Words"):
|
| 95 |
+
st.write(top_words)
|
| 96 |
+
|
| 97 |
+
with st.expander("๐ Relationship Graph"):
|
| 98 |
+
display_relationship_graph(top_words)
|
| 99 |
|
| 100 |
context_words = extract_context_words(text_without_timestamps, top_words)
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
with st.expander("๐ Context Graph"):
|
| 103 |
+
display_context_graph(context_words)
|
| 104 |
+
|
| 105 |
+
with st.expander("๐ Context Table"):
|
| 106 |
+
display_context_table(context_words)
|