# Gerekli kütüphaneleri içe aktar import nltk from nltk import * from nltk.corpus import stopwords from nltk.tokenize import word_tokenize import string import stylecloud from PIL import Image import matplotlib.pyplot as plt # NLTK kütüphanesinden gerekli bileşenleri indir nltk.download('stopwords') nltk.download('punkt') def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png', icon_name='fas fa-coffe', lang='english'): # Metni dosyadan oku with open(file_path, 'r', encoding='utf-8') as f: text = f.read() # Türkçe stopwords listesini yükle stop_words = set(stopwords.words(lang)) # Noktalama işaretlerini kaldır translator = str.maketrans('', '', string.punctuation) text = text.translate(translator) # Metni tokenlere ayır ve küçük harfe çevir tokens = word_tokenize(text.lower(), language=lang) # Stopwords'ü filtrele filtered_tokens = [word for word in tokens if word not in stop_words] # Filtrelenmiş tokenleri birleştir processed_text = ' '.join(filtered_tokens) # StyleCloud oluştur stylecloud.gen_stylecloud(text=processed_text, icon_name=icon_name, output_name=output_name) # Oluşturulan StyleCloud'u göster im = Image.open(output_name) plt.figure(figsize=(10, 10)) plt.imshow(im) plt.axis('off') # Eksenleri gizle plt.show() import streamlit as st import stylecloud def create_stylecloud(text, language, icon): output_file = "stylecloud.png" stylecloud.gen_stylecloud(text=text, icon_name=icon, output_name=output_file) return output_file st.title("WordCloud Creator") file = st.file_uploader("Text File Import", type=["txt"]) if file is not None: text = file.getvalue().decode("utf-8") language = st.radio("Language", ["tr", "en"]) icon_options = [ "fas fa-car", "fas fa-star", "fas fa-trophy", "fas fa-heart", "fas fa-wifi", "fas fa-laptop", "fas fa-coffee", "fas fa-radio", "fas fa-snowflake", "fas fa-apple", "fas fa-basketball-ball", "fas fa-bell", "fas fa-bicycle", "fas fa-binoculars", "fas fa-birthday-cake", "fas fa-blender", "fas fa-bomb", "fas fa-book", "fas fa-bowling-ball", "fas fa-box", "fas fa-bread-slice", "fas fa-briefcase", "fas fa-broom", "fas fa-brush", "fas fa-bug", "fas fa-building", "fas fa-bullhorn", "fas fa-bullseye", "fas fa-bus", "fas fa-calculator", "fas fa-calendar", "fas fa-camera", "fas fa-campground", "fas fa-candy-cane", "fas fa-carrot", "fas fa-cat", "fas fa-chair", "fas fa-chess", "fas fa-chess-king", "fas fa-chess-knight", "fas fa-chess-pawn", "fas fa-chess-queen", "fas fa-chess-rook", "fas fa-child", "fas fa-church", "fas fa-circle", "fas fa-city", "fas fa-clipboard", "fas fa-clock", "fas fa-cloud", "fas fa-cloud-moon", "fas fa-cloud-sun", "fas fa-cocktail", "fas fa-code", "fas fa-coins", "fas fa-compass", "fas fa-cookie", "fas fa-couch", "fas fa-crown", "fas fa-cube", "fas fa-database", "fas fa-desktop", "fas fa-dice", "fas fa-dog", "fas fa-dragon", "fas fa-drum", "fas fa-dumbbell", "fas fa-envelope", "fas fa-eye", "fas fa-fan", "fas fa-feather", "fas fa-fighter-jet", "fas fa-fire", "fas fa-fire-extinguisher", "fas fa-flag", "fas fa-flask", "fas fa-football-ball", "fas fa-frog", "fas fa-gamepad", "fas fa-gem", "fas fa-gift", "fas fa-glasses", "fas fa-globe", "fas fa-guitar", "fas fa-hammer", "fas fa-hat-cowboy", "fas fa-headphones", "fas fa-helicopter", "fas fa-home", "fas fa-hourglass", "fas fa-ice-cream", "fas fa-inbox", "fas fa-key", "fas fa-laptop", "fas fa-leaf", "fas fa-lemon", "fas fa-lightbulb", "fas fa-lock", "fas fa-magic", "fas fa-map", "fas fa-microphone", "fas fa-moon", "fas fa-motorcycle", "fas fa-mountain", "fas fa-mug-hot", "fas fa-music", "fas fa-newspaper", "fas fa-palette", "fas fa-paw", "fas fa-peace", "fas fa-pen", "fas fa-penguin", "fas fa-phone", "fas fa-pizza-slice", "fas fa-plane", "fas fa-plant", "fas fa-plug", "fas fa-poo", "fas fa-print", "fas fa-puzzle-piece", "fas fa-robot", "fas fa-rocket", "fas fa-route", "fas fa-rss", "fas fa-satellite", "fas fa-shield-alt", "fas fa-shipping-fast", "fas fa-shoe-prints", "fas fa-skull", "fas fa-smile", "fas fa-space-shuttle", "fas fa-spider", "fas fa-sun", "fas fa-swatchbook", "fas fa-sword", "fas fa-table-tennis", "fas fa-tag", "fas fa-taxi", "fas fa-teeth", "fas fa-theater-masks", "fas fa-thermometer", "fas fa-toolbox", "fas fa-train", "fas fa-tree", "fas fa-tshirt", "fas fa-umbrella", "fas fa-utensils", "fas fa-venus", "fas fa-virus", "fas fa-walking", "fas fa-water", "fas fa-webcam", "fas fa-wine-bottle", "fas fa-wrench", "fas fa-yin-yang", "fas fa-anchor", "fas fa-battery-full", "fas fa-bowling-pins", "fas fa-brain", "fas fa-bugle", "fas fa-campfire", "fas fa-chess-bishop", "fas fa-cloud-showers-heavy", "fas fa-crow", "fas fa-dice-d20", "fas fa-feather-alt", "fas fa-fighter-jet", "fas fa-film", "fas fa-football-helmet", "fas fa-frog", "fas fa-funnel-dollar", "fas fa-gas-pump", "fas fa-gifts", "fas fa-glasses", "fas fa-hiking", "fas fa-ice-skate", "fas fa-laptop-medical", "fas fa-mitten", "fas fa-mosque", "fas fa-oil-can", "fas fa-palette", "fas fa-parachute-box", "fas fa-pepper-hot", "fas fa-piggy-bank", "fas fa-robot", "fas fa-route", "fas fa-ruler", "fas fa-ruler-combined", "fas fa-shapes", "fas fa-skating", "fas fa-sleigh", "fas fa-smoking", "fas fa-snowboarding", "fas fa-snowplow", "fas fa-stethoscope", "fas fa-stroopwafel", "fas fa-subway", "fas fa-swatchbook", "fas fa-swimmer", "fas fa-tachometer-alt", "fas fa-theater-masks", "fas fa-tractor", "fas fa-tree-decorated", "fas fa-tree-large", "fas fa-truck-monster", "fas fa-tv-retro", "fas fa-umbrella-beach", "fas fa-unicorn", "fas fa-user-astronaut", "fas fa-user-ninja", "fas fa-user-secret", "fas fa-volleyball-ball", "fas fa-walking", "fas fa-wind", "fas fa-window-maximize", "fas fa-windsock", "fas fa-wine-glass", "fas fa-wizard-hat", "fas fa-yen-sign", "fas fa-zeppelin" ] icon = st.selectbox("Select Icon", icon_options, index=1) if st.button("Create"): output_file = create_stylecloud(text, language, icon) st.markdown(f"### [Download WordCloud](./{output_file})") image = Image.open(output_file) st.image(image, caption='WordCloud', use_column_width=True)