Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -108,18 +108,6 @@ def apply_font_to_all_text(fig):
|
|
| 108 |
|
| 109 |
return fig
|
| 110 |
|
| 111 |
-
def save_radar_chart_image(fig):
|
| 112 |
-
"""使用 kaleido 輸出 png 的記憶體檔案"""
|
| 113 |
-
img_bytes = pio.to_image(fig, format="png", engine="kaleido")
|
| 114 |
-
return img_bytes
|
| 115 |
-
|
| 116 |
-
def create_composite_image(fig, student):
|
| 117 |
-
"""使用 PIL 合成圖片,確保學生的成績在最上層"""
|
| 118 |
-
img_bytes = pio.to_image(fig, format="png", engine="kaleido")
|
| 119 |
-
img = Image.open(BytesIO(img_bytes)).convert("RGBA")
|
| 120 |
-
background = Image.new('RGBA', img.size, (255, 255, 255, 255))
|
| 121 |
-
composite = Image.alpha_composite(background, img)
|
| 122 |
-
return composite
|
| 123 |
|
| 124 |
def main():
|
| 125 |
st.title('學生成績雷達圖產生器')
|
|
@@ -144,28 +132,7 @@ def main():
|
|
| 144 |
st.plotly_chart(fig, use_container_width=True)
|
| 145 |
except Exception as e:
|
| 146 |
st.error(f"生成雷達圖時發生錯誤:{e}")
|
| 147 |
-
|
| 148 |
-
st.write("### 批次下載雷達圖")
|
| 149 |
-
comparison_rows = st.multiselect("選擇比較對象(可多選,如班平均或區標)", df['姓名'].tolist())
|
| 150 |
-
|
| 151 |
-
if comparison_rows:
|
| 152 |
-
st.write("### 選擇要下載的圖片")
|
| 153 |
-
|
| 154 |
-
image_bytes = {}
|
| 155 |
-
for student in df['姓名']:
|
| 156 |
-
if student in comparison_rows:
|
| 157 |
-
continue
|
| 158 |
-
|
| 159 |
-
fig = create_radar_chart(df, [student] + comparison_rows, selected_columns)
|
| 160 |
-
fig = apply_font_to_all_text(fig)
|
| 161 |
-
image_bytes[student] = create_composite_image(fig, student)
|
| 162 |
-
|
| 163 |
-
cols = st.columns(3) # 排成三列
|
| 164 |
-
for i, student in enumerate(image_bytes.keys()):
|
| 165 |
-
with cols[i % 3]:
|
| 166 |
-
st.image(image_bytes[student], use_container_width=True)
|
| 167 |
-
st.text(f"下載 {student}")
|
| 168 |
-
|
| 169 |
if __name__ == "__main__":
|
| 170 |
import numpy as np
|
| 171 |
main()
|
|
|
|
| 108 |
|
| 109 |
return fig
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
def main():
|
| 113 |
st.title('學生成績雷達圖產生器')
|
|
|
|
| 132 |
st.plotly_chart(fig, use_container_width=True)
|
| 133 |
except Exception as e:
|
| 134 |
st.error(f"生成雷達圖時發生錯誤:{e}")
|
| 135 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
if __name__ == "__main__":
|
| 137 |
import numpy as np
|
| 138 |
main()
|