Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -110,9 +110,9 @@ def apply_font_to_all_text(fig):
|
|
| 110 |
|
| 111 |
|
| 112 |
def save_radar_chart_image(fig):
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
def create_composite_image(fig, student):
|
| 118 |
"""使用 PIL 合成圖片,確保學生的成績在最上層"""
|
|
@@ -154,19 +154,18 @@ def main():
|
|
| 154 |
|
| 155 |
image_bytes = {}
|
| 156 |
for student in df['姓名']:
|
| 157 |
-
|
| 158 |
continue
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
cols = st.columns(3) # 排成三列
|
| 165 |
for i, student in enumerate(image_bytes.keys()):
|
| 166 |
with cols[i % 3]:
|
| 167 |
st.image(image_bytes[student], use_container_width=True)
|
| 168 |
st.text(f"下載 {student}") # 使用 st.text 顯示文字
|
| 169 |
-
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|
| 172 |
import numpy as np
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
def save_radar_chart_image(fig):
|
| 113 |
+
"""使用 kaleido 輸出 png 的記憶體檔案"""
|
| 114 |
+
img_bytes = pio.to_image(fig, format="png", engine="kaleido")
|
| 115 |
+
return img_bytes
|
| 116 |
|
| 117 |
def create_composite_image(fig, student):
|
| 118 |
"""使用 PIL 合成圖片,確保學生的成績在最上層"""
|
|
|
|
| 154 |
|
| 155 |
image_bytes = {}
|
| 156 |
for student in df['姓名']:
|
| 157 |
+
if student in comparison_rows:
|
| 158 |
continue
|
| 159 |
|
| 160 |
+
fig = create_radar_chart(df, [student] + comparison_rows, selected_columns)
|
| 161 |
+
fig = apply_font_to_all_text(fig)
|
| 162 |
+
image_bytes[student] = create_composite_image(fig, student)
|
| 163 |
+
|
| 164 |
cols = st.columns(3) # 排成三列
|
| 165 |
for i, student in enumerate(image_bytes.keys()):
|
| 166 |
with cols[i % 3]:
|
| 167 |
st.image(image_bytes[student], use_container_width=True)
|
| 168 |
st.text(f"下載 {student}") # 使用 st.text 顯示文字
|
|
|
|
| 169 |
|
| 170 |
if __name__ == "__main__":
|
| 171 |
import numpy as np
|