calculate / app.py
Joey889's picture
Create app.py
f3fcbb0 verified
import gradio as gr
def calculate_grade(att_weeks, ass_count, mid, fin):
# 邏輯計算
att_score = (att_weeks / 18) * 100 * 0.50
ass_score = (ass_count / 18) * 100 * 0.20
mid_weighted = mid * 0.10
fin_weighted = fin * 0.20
total = att_score + ass_score + mid_weighted + fin_weighted
# 準備結果文字
status = "✅ PASS - 及格" if total >= 60 else "🛑 FAIL - 不及格"
result_text = f"""
### 📊 計算結果
- **最終總分:{total:.2f} 分**
- **判定結果:{status}**
---
#### 詳細得分明細:
- 出席得分:{att_score:.1f} / 50
- 作業得分:{ass_score:.1f} / 20
- 期中得分:{mid_weighted:.1f} / 10
- 期末得分:{fin_weighted:.1f} / 20
"""
return result_text
# 建立 Gradio 介面
with gr.Blocks() as demo:
gr.Markdown("# 🎓 18週課程成績直覺計算器")
gr.Markdown("請輸入你的各項成績,系統將自動換算加權總分。")
with gr.Row():
att_input = gr.Slider(0, 18, step=1, label="📍 出席週數 (0-18)")
ass_input = gr.Slider(0, 18, step=1, label="📝 作業完成次數 (0-18)")
with gr.Row():
mid_input = gr.Number(label="📝 期中考分數 (0-100)", value=0)
fin_input = gr.Number(label="📝 期末考分數 (0-100)", value=0)
calc_btn = gr.Button("計算總分", variant="primary")
output = gr.Markdown()
# 綁定按鈕動作
calc_btn.click(
fn=calculate_grade,
inputs=[att_input, ass_input, mid_input, fin_input],
outputs=output
)
demo.launch()