Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
from
|
4 |
-
from nltk.tokenize import word_tokenize
|
5 |
-
from nltk.probability import FreqDist
|
6 |
-
import matplotlib.pyplot as plt
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|