awacke1 commited on
Commit
cf04254
1 Parent(s): 3e92400

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import re
3
  import nltk
 
4
  from nltk.corpus import stopwords
5
  from nltk import FreqDist
6
  from graphviz import Digraph
@@ -63,10 +64,26 @@ def display_context_table(context_words):
63
  table += f"| {before if before else ''} | {high} | {after if after else ''} |\n"
64
  st.markdown(table)
65
 
 
 
 
 
 
 
 
 
66
  uploaded_file = st.file_uploader("Choose a .txt file", type=['txt'])
67
 
68
- if uploaded_file:
 
 
 
 
69
  file_text = uploaded_file.read().decode("utf-8")
 
 
 
 
70
  text_without_timestamps = remove_timestamps(file_text)
71
 
72
  top_words = extract_high_information_words(text_without_timestamps, 10)
@@ -79,6 +96,6 @@ if uploaded_file:
79
  context_words = extract_context_words(text_without_timestamps, top_words)
80
  st.markdown("**Context Graph:**")
81
  display_context_graph(context_words)
82
-
83
  st.markdown("**Context Table:**")
84
  display_context_table(context_words)
 
1
  import streamlit as st
2
  import re
3
  import nltk
4
+ import os
5
  from nltk.corpus import stopwords
6
  from nltk import FreqDist
7
  from graphviz import Digraph
 
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
  uploaded_file = st.file_uploader("Choose a .txt file", type=['txt'])
76
 
77
+ example_text = load_example_files()
78
+
79
+ if example_text:
80
+ file_text = example_text
81
+ elif uploaded_file:
82
  file_text = uploaded_file.read().decode("utf-8")
83
+ else:
84
+ file_text = ""
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)
 
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.markdown("**Context Table:**")
101
  display_context_table(context_words)