Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,87 +0,0 @@
|
|
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 |
-
with open(file = "style.txt",mode="r",encoding="utf-8") as file :
|
68 |
-
icon_options = file.read().split(",")
|
69 |
-
icon_options = list(map(lambda x : x.replace("'",""),icon_options))
|
70 |
-
icon_options = list(map(lambda x : "fas "+x ,icon_options))
|
71 |
-
|
72 |
-
icon = st.selectbox("Icon Selection", icon_options, index=1)
|
73 |
-
|
74 |
-
if st.button("Create"):
|
75 |
-
output_file = create_stylecloud(text, language, icon)
|
76 |
-
st.success(f"Here is your file: {output_file}")
|
77 |
-
|
78 |
-
image = Image.open(output_file)
|
79 |
-
st.image(image, caption='WordCloud', use_column_width=True)
|
80 |
-
|
81 |
-
with open(output_file, "rb") as file:
|
82 |
-
btn = st.download_button(
|
83 |
-
label="Download WordCloud",
|
84 |
-
data=file,
|
85 |
-
file_name=output_file,
|
86 |
-
mime="image/png"
|
87 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|