Spaces:
Runtime error
Runtime error
Claude commited on
fix: 대기실 중복 버튼, 빈 데이터 안내, AI 오류 처리, 데이터 한도 경고
Browse files- lobby.py: 대기실에서 대기실로 이동하는 무의미한 버튼 제거
- teacher_records.py: 데이터 없을 때 안내 메시지 표시,
DASHBOARD_FETCH_LIMIT 초과 시 일부만 다운로드됨 경고
- teacher_hint.py: AI 호출 try/except 처리, 네트워크 오류 시 st.error 표시
- teacher_summary.py: AI 호출 try/except 처리, 네트워크 오류 시 st.error 표시
https://claude.ai/code/session_016DE3uHLsVmA5Uv7gZGGaKT
- components/teacher_hint.py +10 -5
- components/teacher_records.py +16 -11
- components/teacher_summary.py +9 -5
- views/lobby.py +1 -5
components/teacher_hint.py
CHANGED
|
@@ -36,17 +36,22 @@ def render_hint_section(supabase, room_name, user_role, student_name, current_to
|
|
| 36 |
with st.spinner("✍️ 예리한 질문을 작성하고 있습니다..."):
|
| 37 |
context = "\n".join(df_all['content'].tail(5).tolist()) if not df_all.empty else "대화 없음"
|
| 38 |
prompt = build_hint_prompt(act_type, current_topic, context)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if res_text:
|
| 44 |
st.session_state['hint_input_widget'] = res_text.strip().split('\n')[0]
|
| 45 |
st.session_state['ai_hint_manual_mode'] = False
|
| 46 |
st.toast("✅ 힌트 작성 완료!", icon="🎉")
|
| 47 |
else:
|
| 48 |
st.session_state['ai_hint_manual_mode'] = True
|
| 49 |
-
|
|
|
|
| 50 |
else:
|
| 51 |
st.session_state['ai_hint_manual_mode'] = True
|
| 52 |
|
|
|
|
| 36 |
with st.spinner("✍️ 예리한 질문을 작성하고 있습니다..."):
|
| 37 |
context = "\n".join(df_all['content'].tail(5).tolist()) if not df_all.empty else "대화 없음"
|
| 38 |
prompt = build_hint_prompt(act_type, current_topic, context)
|
| 39 |
+
try:
|
| 40 |
+
res_text = generate_ai_response(
|
| 41 |
+
prompt, model_name=AI_MODEL_NAME, api_key=get_secret("GEMINI_API_KEY", ""),
|
| 42 |
+
log_message="AI 힌트 생성 실패", room_name=room_name,
|
| 43 |
+
)
|
| 44 |
+
except Exception as e:
|
| 45 |
+
st.error(f"🚨 AI 호출 중 오류가 발생했습니다: {e}")
|
| 46 |
+
res_text = None
|
| 47 |
if res_text:
|
| 48 |
st.session_state['hint_input_widget'] = res_text.strip().split('\n')[0]
|
| 49 |
st.session_state['ai_hint_manual_mode'] = False
|
| 50 |
st.toast("✅ 힌트 작성 완료!", icon="🎉")
|
| 51 |
else:
|
| 52 |
st.session_state['ai_hint_manual_mode'] = True
|
| 53 |
+
if res_text is not None:
|
| 54 |
+
st.toast("🚨 AI 호출 오류: 수동 모드로 전환되었습니다.", icon="❌")
|
| 55 |
else:
|
| 56 |
st.session_state['ai_hint_manual_mode'] = True
|
| 57 |
|
components/teacher_records.py
CHANGED
|
@@ -3,20 +3,25 @@ import io
|
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
|
|
|
|
| 6 |
from utils import get_kst_now
|
| 7 |
|
| 8 |
|
| 9 |
@st.fragment
|
| 10 |
def render_records_section(room_name, act_type, df_all):
|
| 11 |
st.subheader("📥 활동 데이터 다운로드")
|
| 12 |
-
if
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
from config import DASHBOARD_FETCH_LIMIT
|
| 7 |
from utils import get_kst_now
|
| 8 |
|
| 9 |
|
| 10 |
@st.fragment
|
| 11 |
def render_records_section(room_name, act_type, df_all):
|
| 12 |
st.subheader("📥 활동 데이터 다운로드")
|
| 13 |
+
if df_all.empty:
|
| 14 |
+
st.info(f"아직 {act_type} 데이터가 없습니다. 학생들이 의견을 제출하면 다운로드할 수 있습니다.")
|
| 15 |
+
return
|
| 16 |
+
if len(df_all) >= DASHBOARD_FETCH_LIMIT:
|
| 17 |
+
st.warning(f"⚠️ 의견이 {DASHBOARD_FETCH_LIMIT}개 이상입니다. 최근 {DASHBOARD_FETCH_LIMIT}개만 다운로드됩니다.")
|
| 18 |
+
EXCLUDE_COLS = {'user_id', 'ip_address', 'created_at'}
|
| 19 |
+
export_df = df_all.drop(columns=[c for c in EXCLUDE_COLS if c in df_all.columns])
|
| 20 |
+
buffer = io.BytesIO()
|
| 21 |
+
with pd.ExcelWriter(buffer, engine='openpyxl') as writer:
|
| 22 |
+
export_df.to_excel(writer, index=False)
|
| 23 |
+
st.download_button(
|
| 24 |
+
f"{act_type} 전체 활동 로그 (Excel)",
|
| 25 |
+
data=buffer.getvalue(),
|
| 26 |
+
file_name=f"{room_name}_log_{get_kst_now().strftime('%Y%m%d_%H%M')}.xlsx",
|
| 27 |
+
)
|
components/teacher_summary.py
CHANGED
|
@@ -20,14 +20,18 @@ def render_summary_section(room_name, act_type, current_topic, df_all):
|
|
| 20 |
for _, row in df_all.iterrows()
|
| 21 |
])
|
| 22 |
prompt = build_summary_prompt(act_type, current_topic, full_history)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if res_text:
|
| 28 |
st.session_state['ai_report_text'] = compact_ai_report_output(res_text)
|
| 29 |
st.toast("✅ 리포트 작성 완료!", icon="🎉")
|
| 30 |
-
|
| 31 |
st.toast("🚨 AI 호출 오류가 발생했습니다.", icon="❌")
|
| 32 |
else:
|
| 33 |
st.toast("🚨 분석할 데이터가 없습니다.", icon="⚠️")
|
|
|
|
| 20 |
for _, row in df_all.iterrows()
|
| 21 |
])
|
| 22 |
prompt = build_summary_prompt(act_type, current_topic, full_history)
|
| 23 |
+
try:
|
| 24 |
+
res_text = generate_ai_response(
|
| 25 |
+
prompt, model_name=AI_MODEL_NAME, api_key=get_secret("GEMINI_API_KEY", ""),
|
| 26 |
+
log_message="AI 요약 리포트 생성 실패", room_name=room_name,
|
| 27 |
+
)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
st.error(f"🚨 AI 호출 중 오류가 발생했습니다: {e}")
|
| 30 |
+
res_text = None
|
| 31 |
if res_text:
|
| 32 |
st.session_state['ai_report_text'] = compact_ai_report_output(res_text)
|
| 33 |
st.toast("✅ 리포트 작성 완료!", icon="🎉")
|
| 34 |
+
elif res_text is not None:
|
| 35 |
st.toast("🚨 AI 호출 오류가 발생했습니다.", icon="❌")
|
| 36 |
else:
|
| 37 |
st.toast("🚨 분석할 데이터가 없습니다.", icon="⚠️")
|
views/lobby.py
CHANGED
|
@@ -7,17 +7,13 @@ from config import AUTO_JOIN_ON_REFRESH
|
|
| 7 |
def render_lobby_page(supabase, user_role, teacher_auth, room_name, student_number):
|
| 8 |
admin_auth = st.session_state.get('admin_auth', False)
|
| 9 |
if admin_auth and teacher_auth:
|
| 10 |
-
col_title, col_btn1
|
| 11 |
with col_title:
|
| 12 |
st.title("🚪 말자취(Talk-Trace) AI 대기실")
|
| 13 |
with col_btn1:
|
| 14 |
if st.button("📝 ID 요청 수락", use_container_width=True):
|
| 15 |
st.session_state['page'] = "admin_approval"
|
| 16 |
st.rerun()
|
| 17 |
-
with col_btn2:
|
| 18 |
-
if st.button("🚪 말자취 AI 대기실", use_container_width=True):
|
| 19 |
-
st.session_state['page'] = "lobby"
|
| 20 |
-
st.rerun()
|
| 21 |
else:
|
| 22 |
st.title("🚪 말자취(Talk-Trace) AI 대기실")
|
| 23 |
if user_role == "교사" and not teacher_auth:
|
|
|
|
| 7 |
def render_lobby_page(supabase, user_role, teacher_auth, room_name, student_number):
|
| 8 |
admin_auth = st.session_state.get('admin_auth', False)
|
| 9 |
if admin_auth and teacher_auth:
|
| 10 |
+
col_title, col_btn1 = st.columns([6, 2])
|
| 11 |
with col_title:
|
| 12 |
st.title("🚪 말자취(Talk-Trace) AI 대기실")
|
| 13 |
with col_btn1:
|
| 14 |
if st.button("📝 ID 요청 수락", use_container_width=True):
|
| 15 |
st.session_state['page'] = "admin_approval"
|
| 16 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
st.title("🚪 말자취(Talk-Trace) AI 대기실")
|
| 19 |
if user_role == "교사" and not teacher_auth:
|