File size: 2,317 Bytes
1e87369
a4c52ed
 
 
 
 
 
 
c7f4293
a4c52ed
 
 
 
 
1e87369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1931174
1e87369
1931174
1e87369
c54cdae
dd24d58
1e87369
c54cdae
 
 
 
 
a4c52ed
1e87369
e6ee4a4
a4c52ed
1e87369
 
a4c52ed
 
 
1e87369
 
 
a4c52ed
1e87369
 
 
1931174
1e87369
 
 
 
c54cdae
1931174
1e87369
 
 
 
 
 
 
 
 
 
c54cdae
891bc40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Gerekli kütüphaneleri içe aktar
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
import string
import stylecloud
from PIL import Image
import streamlit as st
import os

# NLTK kütüphanesinden gerekli bileşenleri indir
nltk.download('stopwords')
nltk.download('punkt')

# İkon seçeneklerini belirle
ikon_secenekleri = {
    "Araba": "fas fa-car",
    "Ay-Yıldız": "fas fa-star-and-crescent",
    "Zil": "fas fa-trophy",
    "Taç": "fas fa-crown",
    "Kahve": "fas fa-coffee",
    "Radyo": "fas fa-radio",
    "Yıldız ve Hilal": "fas fa-star-and-crescent",
    "Kupa": "fas fa-trophy",
    "Kalp": "fas fa-heart",
    "Kitap": "fas fa-book",
    "Elmas": "fas fa-gem",
    "Kamera": "fas fa-camera",
    "Bisiklet": "fas fa-bicycle",
    "Müzik": "fas fa-music",
    "Palet": "fas fa-palette"
}

# Ön işleme ve stylecloud oluşturma fonksiyonu
def create_stylecloud(text, language, icon):
    # Geçici bir stylecloud dosyası oluştur
    output_file = "stylecloud.png"
    
    # StyleCloud oluştur
    stylecloud.gen_stylecloud(text=text,
                              icon_name=icon,
                              output_name=output_file)
    
    return output_file

# Streamlit uygulamasını oluştur
st.title("WordCloud Oluşturucu")

# Dosya yükleme
file = st.file_uploader("Metin Dosyası Yükle", type=["txt"])

if file is not None:
    text = file.getvalue().decode("utf-8")

    # Dil seçimi
    language = st.radio("Dil Seçimi", ["tr", "en"], index=0)
    
    # İkon seçimi
    icon_selection = st.selectbox("İkon Seçimi", list(ikon_secenekleri.keys()))
    icon = ikon_secenekleri[icon_selection]

    if st.button("Oluştur"):
        output_file = create_stylecloud(text, language, icon)
        
        # Oluşturulan StyleCloud'u göster ve indirme bağlantısını sun
        image = Image.open(output_file)
        st.image(image, caption='WordCloud', use_column_width=True)
        
        with open(output_file, "rb") as file:
            btn = st.download_button(
                label="Download WordCloud",
                data=file,
                file_name=output_file,
                mime="image/png"
            )

        # Geçici dosyayı sil
        if os.path.exists(output_file):
            os.remove(output_file)