Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,6 @@ from PIL import Image
|
|
8 |
import matplotlib.pyplot as plt
|
9 |
import streamlit as st
|
10 |
import os
|
11 |
-
import base64
|
12 |
-
import os
|
13 |
-
|
14 |
-
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
15 |
-
STATIC_DIR = os.path.join(BASE_DIR, 'static')
|
16 |
|
17 |
# NLTK kütüphanesinden gerekli bileşenleri indir
|
18 |
nltk.download('stopwords')
|
@@ -52,23 +47,13 @@ def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png',
|
|
52 |
plt.show()
|
53 |
|
54 |
def create_stylecloud(text, language, icon):
|
55 |
-
|
56 |
-
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
output_file
|
63 |
-
|
64 |
-
stylecloud.gen_stylecloud(text=text, icon_name=icon, output_name=output_file)
|
65 |
-
|
66 |
-
# Dosyayı Base64 olarak kodla
|
67 |
-
with open(output_file, "rb") as file:
|
68 |
-
data = file.read()
|
69 |
-
encoded = base64.b64encode(data).decode()
|
70 |
-
|
71 |
-
return encoded
|
72 |
|
73 |
st.title("WordCloud Creator")
|
74 |
|
@@ -107,15 +92,11 @@ if file is not None:
|
|
107 |
icon = [icon for icon, label in icon_options if label == icon_selection][0]
|
108 |
|
109 |
if st.button("Create"):
|
110 |
-
|
111 |
-
st.markdown(
|
112 |
-
f"""
|
113 |
-
<a href="data:application/octet-stream;base64,{encoded_image}" download="stylecloud.png">
|
114 |
-
<button>Download WordCloud</button>
|
115 |
-
</a>
|
116 |
-
""",
|
117 |
-
unsafe_allow_html=True
|
118 |
-
)
|
119 |
|
120 |
-
image = Image.open(
|
121 |
st.image(image, caption='WordCloud', use_column_width=True)
|
|
|
|
|
|
|
|
8 |
import matplotlib.pyplot as plt
|
9 |
import streamlit as st
|
10 |
import os
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# NLTK kütüphanesinden gerekli bileşenleri indir
|
13 |
nltk.download('stopwords')
|
|
|
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 |
st.title("WordCloud Creator")
|
59 |
|
|
|
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 |
+
# Ensure the file is deleted after display
|
101 |
+
if os.path.exists(output_file):
|
102 |
+
os.remove(output_file)
|