Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,13 +47,16 @@ def preprocess_and_create_stylecloud(file_path, output_name='stylecloud.png',
|
|
47 |
plt.show()
|
48 |
|
49 |
def create_stylecloud(text, language, icon):
|
50 |
-
|
51 |
|
52 |
stylecloud.gen_stylecloud(text=text,
|
53 |
icon_name=icon,
|
54 |
output_name=output_file)
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
st.title("WordCloud Creator")
|
59 |
|
@@ -92,10 +95,17 @@ if file is not None:
|
|
92 |
icon = [icon for icon, label in icon_options if label == icon_selection][0]
|
93 |
|
94 |
if st.button("Create"):
|
95 |
-
|
96 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
image = Image.open(
|
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):
|
|
|
47 |
plt.show()
|
48 |
|
49 |
def create_stylecloud(text, language, icon):
|
50 |
+
output_file = "static/stylecloud.png"
|
51 |
|
52 |
stylecloud.gen_stylecloud(text=text,
|
53 |
icon_name=icon,
|
54 |
output_name=output_file)
|
55 |
+
# Dosyayı Base64 olarak kodla
|
56 |
+
with open(output_file, "rb") as file:
|
57 |
+
data = file.read()
|
58 |
+
encoded = base64.b64encode(data).decode()
|
59 |
+
return encoded
|
60 |
|
61 |
st.title("WordCloud Creator")
|
62 |
|
|
|
95 |
icon = [icon for icon, label in icon_options if label == icon_selection][0]
|
96 |
|
97 |
if st.button("Create"):
|
98 |
+
encoded_image = create_stylecloud(text, language, icon)
|
99 |
+
st.markdown(
|
100 |
+
f"""
|
101 |
+
<a href="data:application/octet-stream;base64,{encoded_image}" download="stylecloud.png">
|
102 |
+
<button>Download WordCloud</button>
|
103 |
+
</a>
|
104 |
+
""",
|
105 |
+
unsafe_allow_html=True
|
106 |
+
)
|
107 |
|
108 |
+
image = Image.open("static/stylecloud.png")
|
109 |
st.image(image, caption='WordCloud', use_column_width=True)
|
110 |
# Ensure the file is deleted after display
|
111 |
if os.path.exists(output_file):
|