yunuseduran commited on
Commit
9d4affc
·
verified ·
1 Parent(s): 114db4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
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
- 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,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
- output_file = create_stylecloud(text, language, icon)
96
- st.markdown(f"### [Download WordCloud](/static/{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):
 
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):