Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -108,6 +108,18 @@ def apply_font_to_all_text(fig):
|
|
| 108 |
|
| 109 |
return fig
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
def main():
|
| 113 |
st.title('學生成績雷達圖產生器')
|
|
@@ -132,6 +144,17 @@ def main():
|
|
| 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
|
|
|
|
| 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 |
st.plotly_chart(fig, use_container_width=True)
|
| 145 |
except Exception as e:
|
| 146 |
st.error(f"生成雷達圖時發生錯誤:{e}")
|
| 147 |
+
|
| 148 |
+
st.write("### 批次繪製個別學生比較圖")
|
| 149 |
+
|
| 150 |
+
individual_students = st.multiselect("選擇要個別比較的學生", df['姓名'].tolist(), key = "student")
|
| 151 |
+
comparison_items = st.multiselect("選擇要比較的項目", df['姓名'].tolist(), key = "item")
|
| 152 |
+
|
| 153 |
+
if individual_students and comparison_items:
|
| 154 |
+
for student in individual_students:
|
| 155 |
+
fig = create_radar_chart(df, [student] + comparison_items, selected_columns)
|
| 156 |
+
st.image(create_composite_image(fig,student), use_column_width=True)
|
| 157 |
+
st.text(f"{student} 與 {', '.join(comparison_items)} 的比較")
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
import numpy as np
|