Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +97 -0
- requirements.txt +10 -0
app.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gerekli kütüphaneleri içe aktar
|
2 |
+
import nltk
|
3 |
+
from nltk.corpus import stopwords
|
4 |
+
from nltk.tokenize import word_tokenize
|
5 |
+
import string
|
6 |
+
import stylecloud
|
7 |
+
from PIL import Image
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
import streamlit as st
|
10 |
+
|
11 |
+
# NLTK kütüphanesinden gerekli bileşenleri indir
|
12 |
+
nltk.download('stopwords')
|
13 |
+
nltk.download('punkt')
|
14 |
+
|
15 |
+
def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png',
|
16 |
+
icon_name='fas fa-laptop', lang='english'):
|
17 |
+
# Metni dosyadan oku
|
18 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
19 |
+
text = f.read()
|
20 |
+
|
21 |
+
# Dil için stopwords listesini yükle
|
22 |
+
stop_words = set(stopwords.words(lang))
|
23 |
+
|
24 |
+
# Noktalama işaretlerini kaldır
|
25 |
+
translator = str.maketrans('', '', string.punctuation)
|
26 |
+
text = text.translate(translator)
|
27 |
+
|
28 |
+
# Metni tokenlere ayır ve küçük harfe çevir
|
29 |
+
tokens = word_tokenize(text.lower(), language=lang)
|
30 |
+
|
31 |
+
# Stopwords'ü filtrele
|
32 |
+
filtered_tokens = [word for word in tokens if word not in stop_words]
|
33 |
+
|
34 |
+
# Filtrelenmiş tokenleri birleştir
|
35 |
+
processed_text = ' '.join(filtered_tokens)
|
36 |
+
|
37 |
+
# StyleCloud oluştur
|
38 |
+
stylecloud.gen_stylecloud(text=processed_text,
|
39 |
+
icon_name=icon_name,
|
40 |
+
output_name=output_name)
|
41 |
+
# Oluşturulan StyleCloud'u göster
|
42 |
+
im = Image.open(output_name)
|
43 |
+
plt.figure(figsize=(10, 10))
|
44 |
+
plt.imshow(im)
|
45 |
+
plt.axis('off') # Eksenleri gizle
|
46 |
+
plt.show()
|
47 |
+
|
48 |
+
def create_stylecloud(text, language, icon):
|
49 |
+
output_file = "stylecloud.png"
|
50 |
+
|
51 |
+
stylecloud.gen_stylecloud(text=text,
|
52 |
+
icon_name=icon,
|
53 |
+
output_name=output_file)
|
54 |
+
|
55 |
+
return output_file
|
56 |
+
|
57 |
+
st.title("WordCloud Creator")
|
58 |
+
|
59 |
+
file = st.file_uploader("Import txt file", type=["txt"])
|
60 |
+
|
61 |
+
if file is not None:
|
62 |
+
text = file.getvalue().decode("utf-8")
|
63 |
+
|
64 |
+
language = st.radio("Language", ["tr", "en"])
|
65 |
+
|
66 |
+
icon_options = [
|
67 |
+
("fas fa-car", "Araba"),
|
68 |
+
("fas fa-star", "Yıldız"),
|
69 |
+
("fas fa-trophy", "Kupa"),
|
70 |
+
("fas fa-heart", "Kalp"),
|
71 |
+
("fas fa-wifi", "WiFi"),
|
72 |
+
("fas fa-laptop", "Dizüstü Bilgisayar"),
|
73 |
+
("fas fa-coffee", "Kahve"),
|
74 |
+
("fas fa-radio", "Radyo"),
|
75 |
+
("fas fa-snowflake", "Kar Tanesi"),
|
76 |
+
("fas fa-apple-alt", "Elma"),
|
77 |
+
("fas fa-bell", "Zil"),
|
78 |
+
("fas fa-bicycle", "Bisiklet"),
|
79 |
+
("fas fa-bolt", "Yıldırım"),
|
80 |
+
("fas fa-book", "Kitap"),
|
81 |
+
("fas fa-bug", "Böcek"),
|
82 |
+
("fas fa-camera", "Kamera"),
|
83 |
+
("fas fa-crown", "Taç"),
|
84 |
+
("fas fa-futbol", "Futbol"),
|
85 |
+
("fas fa-gift", "Hediye")
|
86 |
+
]
|
87 |
+
|
88 |
+
icon_labels = [label for _, label in icon_options]
|
89 |
+
icon_selection = st.selectbox("İkon Seçimi", icon_labels, index=1)
|
90 |
+
icon = [icon for icon, label in icon_options if label == icon_selection][0]
|
91 |
+
|
92 |
+
if st.button("Create"):
|
93 |
+
output_file = create_stylecloud(text, language, icon)
|
94 |
+
st.markdown(f"### [Download WordCloud](./{output_file})")
|
95 |
+
|
96 |
+
image = Image.open(output_file)
|
97 |
+
st.image(image, caption='WordCloud', use_column_width=True)
|
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
|