Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 10 |
+
# NLTK kütüphanesinden gerekli bileşenleri indir
|
| 11 |
+
nltk.download('stopwords')
|
| 12 |
+
nltk.download('punkt')
|
| 13 |
+
|
| 14 |
+
def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png',
|
| 15 |
+
icon_name='fas fa-laptop', lang='english'):
|
| 16 |
+
# Metni dosyadan oku
|
| 17 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 18 |
+
text = f.read()
|
| 19 |
+
|
| 20 |
+
# Türkçe stopwords listesini yükle
|
| 21 |
+
stop_words = set(stopwords.words(lang))
|
| 22 |
+
|
| 23 |
+
# Noktalama işaretlerini kaldır
|
| 24 |
+
translator = str.maketrans('', '', string.punctuation)
|
| 25 |
+
text = text.translate(translator)
|
| 26 |
+
|
| 27 |
+
# Metni tokenlere ayır ve küçük harfe çevir
|
| 28 |
+
tokens = word_tokenize(text.lower(), language=lang)
|
| 29 |
+
|
| 30 |
+
# Stopwords'ü filtrele
|
| 31 |
+
filtered_tokens = [word for word in tokens if word not in stop_words]
|
| 32 |
+
|
| 33 |
+
# Filtrelenmiş tokenleri birleştir
|
| 34 |
+
processed_text = ' '.join(filtered_tokens)
|
| 35 |
+
|
| 36 |
+
# StyleCloud oluştur
|
| 37 |
+
stylecloud.gen_stylecloud(text=processed_text,
|
| 38 |
+
icon_name=icon_name,
|
| 39 |
+
output_name=output_name)
|
| 40 |
+
# Oluşturulan StyleCloud'u göster
|
| 41 |
+
im = Image.open(output_name)
|
| 42 |
+
plt.figure(figsize=(10, 10))
|
| 43 |
+
plt.imshow(im)
|
| 44 |
+
plt.axis('off') # Eksenleri gizle
|
| 45 |
+
plt.show()
|
| 46 |
+
|
| 47 |
+
preprocess_and_create_stylecloud(file_path='AI.txt',
|
| 48 |
+
output_name='computer_ai.png', icon_name='fas fa-laptop', lang='english')
|
| 49 |
+
|
| 50 |
+
import streamlit as st
|
| 51 |
+
import stylecloud
|
| 52 |
+
|
| 53 |
+
def create_stylecloud(text, language, icon):
|
| 54 |
+
output_file = "stylecloud.png"
|
| 55 |
+
|
| 56 |
+
stylecloud.gen_stylecloud(text=text,
|
| 57 |
+
icon_name=icon,
|
| 58 |
+
output_name=output_file)
|
| 59 |
+
|
| 60 |
+
return output_file
|
| 61 |
+
|
| 62 |
+
st.title("StyleCloud Creator")
|
| 63 |
+
|
| 64 |
+
file = st.file_uploader("Import txt file", type=["txt"])
|
| 65 |
+
|
| 66 |
+
if file is not None:
|
| 67 |
+
text = file.getvalue().decode("utf-8")
|
| 68 |
+
|
| 69 |
+
language = st.radio("Language", ["tr", "en"])
|
| 70 |
+
|
| 71 |
+
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']
|
| 72 |
+
icon = st.selectbox("İkon Seçimi", icon_options, index=1)
|
| 73 |
+
|
| 74 |
+
if st.button("Create"):
|
| 75 |
+
output_file = create_stylecloud(text, language, icon)
|
| 76 |
+
st.markdown(f"### [Download StyleCloud](./{output_file})")
|
| 77 |
+
|
| 78 |
+
image = Image.open(output_file)
|
| 79 |
+
st.image(image, caption='StyleCloud', use_column_width=True)
|