# 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)