awacke1 commited on
Commit
6b13e5e
·
1 Parent(s): b1f52ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -49
app.py CHANGED
@@ -1,56 +1,27 @@
1
  import streamlit as st
2
- import nltk
3
- from nltk.corpus import stopwords
4
- from nltk.tokenize import word_tokenize
5
- from nltk.probability import FreqDist
6
- import matplotlib.pyplot as plt
7
 
8
- nltk.download('punkt')
 
9
 
10
- def process_text(text):
11
- # Tokenize the text
12
- tokens = word_tokenize(text)
 
13
 
14
- # Remove stopwords
15
- stop_words = set(stopwords.words("english"))
16
- filtered_tokens = [word for word in tokens if word.lower() not in stop_words]
 
17
 
18
- # Calculate word frequency
19
- fdist = FreqDist(filtered_tokens)
20
 
21
- # Get the top 10 most common words
22
- top_words = fdist.most_common(10)
 
 
23
 
24
- return top_words
25
-
26
-
27
- def main():
28
- st.title("NLTK Graph Visualization")
29
-
30
- # Upload file
31
- uploaded_file = st.file_uploader("Upload a text file", type=["txt"])
32
-
33
- if uploaded_file is not None:
34
- # Read file contents
35
- text = uploaded_file.read().decode("utf-8")
36
-
37
- # Process the text
38
- top_words = process_text(text)
39
-
40
- # Plot word frequency graph
41
- words, frequencies = zip(*top_words)
42
- plt.bar(words, frequencies)
43
- plt.xticks(rotation=45)
44
- plt.xlabel("Words")
45
- plt.ylabel("Frequency")
46
- plt.title("Top 10 Most Common Words")
47
- st.pyplot()
48
-
49
- # Display the top words
50
- st.subheader("Top 10 Most Common Words")
51
- for word, frequency in top_words:
52
- st.write(f"- {word}: {frequency}")
53
-
54
-
55
- if __name__ == "__main__":
56
- main()
 
1
  import streamlit as st
2
+ import time
3
+ from datetime import datetime
 
 
 
4
 
5
+ # Set the time at the start of the program
6
+ start_time = time.time()
7
 
8
+ # Main loop
9
+ while True:
10
+ # Get the current time
11
+ now = time.time()
12
 
13
+ # Check if 15 seconds have passed
14
+ if now - start_time >= 15:
15
+ # Refresh the screen
16
+ st.experimental_rerun()
17
 
18
+ # Show the text area
19
+ text_input = st.text_area('Crowdsource')
20
 
21
+ # When data is saved there, append it to a "Log.txt" file
22
+ if text_input:
23
+ with open('Log.txt', 'a') as f:
24
+ f.write(f"{datetime.now()}: {text_input}\n")
25
 
26
+ # Sleep for a while to prevent the loop from running too fast
27
+ time.sleep(1)