aliicemill commited on
Commit
809bda4
·
verified ·
1 Parent(s): f9dd26d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +108 -0
  2. requirements.txt +10 -0
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Importing Libraries
2
+ # author:@aliicemill
3
+ import nltk
4
+ from PIL import Image
5
+ import matplotlib.pyplot as plt
6
+ import streamlit as st
7
+ from nltk.corpus import stopwords
8
+ from nltk.tokenize import word_tokenize
9
+ import string
10
+ import stylecloud
11
+
12
+ # Downloading word clusters
13
+ nltk.download('stopwords')
14
+ nltk.download('punkt')
15
+
16
+ def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png',
17
+ icon_name='fas fa-laptop', lang='english'):
18
+ # read file
19
+ with open(file_path, 'r', encoding='utf-8') as f:
20
+ text = f.read()
21
+
22
+ # represent stopwords
23
+ stop_words = set(stopwords.words(lang))
24
+
25
+ # Remove punctuation marks
26
+ translator = str.maketrans('', '', string.punctuation)
27
+ text = text.translate(translator)
28
+
29
+ # Tokenize the text and convert to lowercase
30
+ tokens = word_tokenize(text.lower(), language=lang)
31
+
32
+ # Filter out stopwords
33
+ filtered_tokens = [word for word in tokens if word not in stop_words]
34
+
35
+ # Join filtered tokens
36
+ processed_text = ' '.join(filtered_tokens)
37
+
38
+ # Create StyleCloud
39
+ stylecloud.gen_stylecloud(text=processed_text,
40
+ icon_name=icon_name,
41
+ output_name=output_name)
42
+ # Show the generated StyleCloud
43
+ im = Image.open(output_name)
44
+ plt.figure(figsize=(10, 10))
45
+ plt.imshow(im)
46
+ plt.axis('off') # Hide axes
47
+ plt.show()
48
+
49
+ def create_stylecloud(text, language, icon):
50
+ output_file = "stylecloud.png"
51
+
52
+ stylecloud.gen_stylecloud(text=text,
53
+ icon_name=icon,
54
+ output_name=output_file)
55
+
56
+ return output_file
57
+
58
+ st.title("WordCloud Creator")
59
+
60
+ file = st.file_uploader("Import txt file", type=["txt"])
61
+
62
+ if file is not None:
63
+ text = file.getvalue().decode("utf-8")
64
+
65
+ language = st.radio("Language", ["tr", "en","fr","de"])
66
+
67
+ icon_options = [
68
+ 'fa-address-book', 'fa-address-card', 'fa-angry', 'fa-arrow-alt-circle-down', 'fa-arrow-alt-circle-left',
69
+ 'fa-arrow-alt-circle-right', 'fa-arrow-alt-circle-up', 'fa-bell', 'fa-bell-slash', 'fa-bookmark', 'fa-building',
70
+ 'fa-calendar', 'fa-calendar-alt', 'fa-calendar-check', 'fa-calendar-minus', 'fa-calendar-plus', 'fa-calendar-times',
71
+ 'fa-caret-square-down', 'fa-caret-square-left', 'fa-caret-square-right', 'fa-caret-square-up', 'fa-chart-bar',
72
+ 'fa-check-circle', 'fa-check-square', 'fa-circle', 'fa-clipboard', 'fa-clock', 'fa-clone', 'fa-closed-captioning',
73
+ 'fa-comment', 'fa-comment-alt', 'fa-comment-dots', 'fa-comments', 'fa-compass', 'fa-copy', 'fa-copyright', 'fa-credit-card',
74
+ 'fa-dizzy', 'fa-dot-circle', 'fa-edit', 'fa-envelope', 'fa-envelope-open', 'fa-eye', 'fa-eye-slash', 'fa-file',
75
+ 'fa-file-alt', 'fa-file-archive', 'fa-file-audio', 'fa-file-code', 'fa-file-excel', 'fa-file-image', 'fa-file-pdf',
76
+ 'fa-file-powerpoint', 'fa-file-video', 'fa-file-word', 'fa-flag', 'fa-flushed', 'fa-folder', 'fa-folder-open', 'fa-frown',
77
+ 'fa-frown-open', 'fa-futbol', 'fa-gem', 'fa-grimace', 'fa-grin', 'fa-grin-alt', 'fa-grin-beam', 'fa-grin-beam-sweat',
78
+ 'fa-grin-hearts', 'fa-grin-squint', 'fa-grin-squint-tears', 'fa-grin-stars', 'fa-grin-tears', 'fa-grin-tongue',
79
+ 'fa-grin-tongue-squint', 'fa-grin-tongue-wink', 'fa-grin-wink', 'fa-hand-lizard', 'fa-hand-paper', 'fa-hand-peace',
80
+ 'fa-hand-point-down', 'fa-hand-point-left', 'fa-hand-point-right', 'fa-hand-point-up', 'fa-hand-pointer', 'fa-hand-rock',
81
+ 'fa-hand-scissors', 'fa-hand-spock', 'fa-handshake', 'fa-hdd', 'fa-heart', 'fa-hospital', 'fa-hourglass', 'fa-id-badge',
82
+ 'fa-id-card', 'fa-image', 'fa-images', 'fa-keyboard', 'fa-kiss', 'fa-kiss-beam', 'fa-kiss-wink-heart', 'fa-laugh',
83
+ 'fa-laugh-beam', 'fa-laugh-squint', 'fa-laugh-wink', 'fa-lemon', 'fa-life-ring', 'fa-lightbulb', 'fa-list-alt',
84
+ 'fa-map', 'fa-meh', 'fa-meh-blank', 'fa-meh-rolling-eyes', 'fa-minus-square', 'fa-money-bill-alt', 'fa-moon',
85
+ 'fa-newspaper', 'fa-object-group', 'fa-object-ungroup', 'fa-paper-plane', 'fa-pause-circle', 'fa-play-circle',
86
+ 'fa-plus-square', 'fa-question-circle', 'fa-registered', 'fa-sad-cry', 'fa-sad-tear', 'fa-save', 'fa-share-square',
87
+ 'fa-smile', 'fa-smile-beam', 'fa-smile-wink', 'fa-snowflake', 'fa-square', 'fa-star', 'fa-star-half', 'fa-sticky-note',
88
+ 'fa-stop-circle', 'fa-sun', 'fa-surprise', 'fa-thumbs-down', 'fa-thumbs-up', 'fa-times-circle', 'fa-tired', 'fa-trash-alt',
89
+ 'fa-user', 'fa-user-circle', 'fa-window-close', 'fa-window-maximize', 'fa-window-minimize', 'fa-window-restore'
90
+ ]
91
+ icon_options = list(map(lambda x : "fas "+x ,icon_options))
92
+
93
+ icon = st.selectbox("Icon Selection", icon_options, index=1)
94
+
95
+ if st.button("Create"):
96
+ output_file = create_stylecloud(text, language, icon)
97
+ st.success(f"Here is your file: {output_file}")
98
+
99
+ image = Image.open(output_file)
100
+ st.image(image, caption='WordCloud', use_column_width=True)
101
+
102
+ with open(output_file, "rb") as file:
103
+ btn = st.download_button(
104
+ label="Download WordCloud",
105
+ data=file,
106
+ file_name=output_file,
107
+ mime="image/png"
108
+ )
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ plotly
3
+ streamlit
4
+ yfinance
5
+ pandas-datareader
6
+ prophet
7
+ nltk
8
+ stylecloud
9
+ pillow==9.4
10
+ Image