Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 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 |
import os
|
| 11 |
|
|
@@ -13,90 +12,75 @@ import os
|
|
| 13 |
nltk.download('stopwords')
|
| 14 |
nltk.download('punkt')
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
# Filtrelenmiş tokenleri birleştir
|
| 36 |
-
processed_text = ' '.join(filtered_tokens)
|
| 37 |
-
|
| 38 |
-
# StyleCloud oluştur
|
| 39 |
-
stylecloud.gen_stylecloud(text=processed_text,
|
| 40 |
-
icon_name=icon_name,
|
| 41 |
-
output_name=output_name)
|
| 42 |
-
# Oluşturulan StyleCloud'u göster
|
| 43 |
-
im = Image.open(output_name)
|
| 44 |
-
plt.figure(figsize=(10, 10))
|
| 45 |
-
plt.imshow(im)
|
| 46 |
-
plt.axis('off') # Eksenleri gizle
|
| 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 |
-
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
if file is not None:
|
| 63 |
text = file.getvalue().decode("utf-8")
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
("fas fa-car", "Araba"),
|
| 69 |
-
("fas fa-star-and-crescent", "Ay Yıldız"),
|
| 70 |
-
("fas fa-star", "Yıldız"),
|
| 71 |
-
("fas fa-trophy", "Kupa"),
|
| 72 |
-
("fas fa-heart", "Kalp"),
|
| 73 |
-
("fas fa-wifi", "WiFi"),
|
| 74 |
-
("fas fa-laptop", "Dizüstü Bilgisayar"),
|
| 75 |
-
("fas fa-coffee", "Kahve"),
|
| 76 |
-
("fas fa-radio", "Radyo"),
|
| 77 |
-
("fas fa-snowflake", "Kar Tanesi"),
|
| 78 |
-
("fas fa-apple-alt", "Elma"),
|
| 79 |
-
("fas fa-bell", "Zil"),
|
| 80 |
-
("fas fa-bicycle", "Bisiklet"),
|
| 81 |
-
("fas fa-bolt", "Yıldırım"),
|
| 82 |
-
("fas fa-book", "Kitap"),
|
| 83 |
-
("fas fa-bug", "Böcek"),
|
| 84 |
-
("fas fa-camera", "Kamera"),
|
| 85 |
-
("fas fa-crown", "Taç"),
|
| 86 |
-
("fas fa-futbol", "Futbol"),
|
| 87 |
-
("fas fa-gift", "Hediye")
|
| 88 |
-
]
|
| 89 |
-
|
| 90 |
-
icon_labels = [label for _, label in icon_options]
|
| 91 |
-
icon_selection = st.selectbox("İkon Seçimi", icon_labels, index=1)
|
| 92 |
-
icon = [icon for icon, label in icon_options if label == icon_selection][0]
|
| 93 |
-
|
| 94 |
-
if st.button("Create"):
|
| 95 |
-
output_file = create_stylecloud(text, language, icon)
|
| 96 |
-
st.markdown(f"### [Download WordCloud](./{output_file})")
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
image = Image.open(output_file)
|
| 99 |
st.image(image, caption='WordCloud', use_column_width=True)
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
if os.path.exists(output_file):
|
| 102 |
-
os.remove(output_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 streamlit as st
|
| 9 |
import os
|
| 10 |
|
|
|
|
| 12 |
nltk.download('stopwords')
|
| 13 |
nltk.download('punkt')
|
| 14 |
|
| 15 |
+
# İkon seçeneklerini belirle
|
| 16 |
+
ikon_secenekleri = {
|
| 17 |
+
"Araba": "fas fa-car",
|
| 18 |
+
"Ay-Yıldız": "fas fa-star-and-crescent",
|
| 19 |
+
"Zil": "fas fa-trophy",
|
| 20 |
+
"Taç": "fas fa-crown",
|
| 21 |
+
"Kahve": "fas fa-coffee",
|
| 22 |
+
"Radyo": "fas fa-radio",
|
| 23 |
+
"Yıldız ve Hilal": "fas fa-star-and-crescent",
|
| 24 |
+
"Kupa": "fas fa-trophy",
|
| 25 |
+
"Kalp": "fas fa-heart",
|
| 26 |
+
"Kitap": "fas fa-book",
|
| 27 |
+
"Elmas": "fas fa-gem",
|
| 28 |
+
"Kamera": "fas fa-camera",
|
| 29 |
+
"Bisiklet": "fas fa-bicycle",
|
| 30 |
+
"Müzik": "fas fa-music",
|
| 31 |
+
"Palet": "fas fa-palette"
|
| 32 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Ön işleme ve stylecloud oluşturma fonksiyonu
|
| 35 |
def create_stylecloud(text, language, icon):
|
| 36 |
+
# Geçici bir stylecloud dosyası oluştur
|
| 37 |
output_file = "stylecloud.png"
|
| 38 |
|
| 39 |
+
# StyleCloud oluştur
|
| 40 |
stylecloud.gen_stylecloud(text=text,
|
| 41 |
icon_name=icon,
|
| 42 |
output_name=output_file)
|
| 43 |
|
| 44 |
return output_file
|
| 45 |
|
| 46 |
+
# Streamlit uygulamasını oluştur
|
| 47 |
+
st.title("StyleCloud Oluşturucu")
|
| 48 |
|
| 49 |
+
# Dosya yükleme
|
| 50 |
+
file = st.file_uploader("Metin Dosyası Yükle", type=["txt"])
|
| 51 |
|
| 52 |
if file is not None:
|
| 53 |
text = file.getvalue().decode("utf-8")
|
| 54 |
+
|
| 55 |
+
# Dil seçimi
|
| 56 |
+
language = st.radio("Dil Seçimi", ["tr", "en"], index=0)
|
| 57 |
|
| 58 |
+
# İkon seçimi
|
| 59 |
+
icon_selection = st.selectbox("İkon Seçimi", list(ikon_secenekleri.keys()))
|
| 60 |
+
icon = ikon_secenekleri[icon_selection]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
if st.button("Oluştur"):
|
| 63 |
+
output_file = create_stylecloud(text, language, icon)
|
| 64 |
+
|
| 65 |
+
# Oluşturulan StyleCloud'u göster ve indirme bağlantısını sun
|
| 66 |
image = Image.open(output_file)
|
| 67 |
st.image(image, caption='WordCloud', use_column_width=True)
|
| 68 |
+
|
| 69 |
+
with open(output_file, "rb") as file:
|
| 70 |
+
btn = st.download_button(
|
| 71 |
+
label="Download WordCloud",
|
| 72 |
+
data=file,
|
| 73 |
+
file_name=output_file,
|
| 74 |
+
mime="image/png"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Geçici dosyayı sil
|
| 78 |
if os.path.exists(output_file):
|
| 79 |
+
os.remove(output_file)
|
| 80 |
+
|
| 81 |
+
# Hugging Face üzerinde Streamlit uygulaması olarak başlat
|
| 82 |
+
if __name__ == '__main__':
|
| 83 |
+
import streamlit.cli as stcli
|
| 84 |
+
import sys
|
| 85 |
+
sys.argv = ["streamlit", "run", __file__]
|
| 86 |
+
sys.exit(stcli.main())
|