wxy01giser commited on
Commit
0b98fea
·
verified ·
1 Parent(s): a9c95cc

Update cluster_insight.py

Browse files
Files changed (1) hide show
  1. cluster_insight.py +8 -1
cluster_insight.py CHANGED
@@ -147,6 +147,12 @@ def auto_select_k(embeddings, max_k=10):
147
  return best_k
148
 
149
 
 
 
 
 
 
 
150
  def cluster_and_visualize(
151
  excel_path: str,
152
  questions=['s1', 's2', 's3', 's4'],
@@ -259,7 +265,8 @@ def cluster_and_visualize(
259
  height=600,
260
  scale=2
261
  )
262
- b64 = base64.b64encode(img_bytes).decode('utf-8')
 
263
  # print(f"{b64}解析成功!")
264
  # return b64, stats
265
  return fig, b64, stats
 
147
  return best_k
148
 
149
 
150
+ def fig_to_base64(fig):
151
+ buffer = BytesIO()
152
+ fig.write_image(buffer, format="png", engine="kaleido") # 此时在Hugging Face环境,kaleido能找到字体
153
+ buffer.seek(0)
154
+ return base64.b64encode(buffer.read()).decode("ascii")
155
+
156
  def cluster_and_visualize(
157
  excel_path: str,
158
  questions=['s1', 's2', 's3', 's4'],
 
265
  height=600,
266
  scale=2
267
  )
268
+ # b64 = base64.b64encode(img_bytes).decode('utf-8')
269
+ b64 = fig_to_base64(fig)
270
  # print(f"{b64}解析成功!")
271
  # return b64, stats
272
  return fig, b64, stats