Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import sys | |
| import os | |
| sys.path.append(os.path.join(os.path.dirname(__file__), 'src')) | |
| from utils import init_supabase | |
| def add_debate_case(): | |
| st.title("π Add Debate Case") | |
| # Initialize Supabase | |
| supabase = init_supabase() | |
| if not supabase: | |
| st.error("β Cannot connect to database") | |
| return | |
| st.markdown("---") | |
| # Form to add debate case | |
| with st.form("add_debate_case_form"): | |
| st.subheader("Add New Debate Case") | |
| # Student ID input | |
| student_id = st.text_input("Student ID (username):", placeholder="e.g., lily, reed") | |
| # Google Doc URL input | |
| google_doc_url = st.text_input("Google Doc URL:", | |
| value="https://docs.google.com/document/d/1J8Unkklwhk778jcARshISK0AdBZ34XikQpeBDAWAxY0/edit", | |
| placeholder="https://docs.google.com/document/d/...") | |
| # Description input | |
| description = st.text_area("Description:", placeholder="Brief description of the debate case") | |
| # Submit button | |
| submitted = st.form_submit_button("Add Debate Case") | |
| if submitted: | |
| if student_id and google_doc_url: | |
| try: | |
| # Insert the debate case | |
| data = { | |
| 'student_id': student_id, | |
| 'google_doc_link': google_doc_url, | |
| 'description': description | |
| } | |
| response = supabase.table('student_debate_case').insert(data).execute() | |
| if response.data: | |
| st.success(f"β Successfully added debate case for {student_id}") | |
| st.write("**Added data:**") | |
| st.json(response.data[0]) | |
| else: | |
| st.error("β Failed to add debate case") | |
| except Exception as e: | |
| st.error(f"β Error adding debate case: {str(e)}") | |
| else: | |
| st.warning("β οΈ Please fill in Student ID and Google Doc URL") | |
| st.markdown("---") | |
| # Show existing debate cases | |
| st.subheader("Current Debate Cases") | |
| try: | |
| response = supabase.table('student_debate_case').select('*').execute() | |
| if response.data: | |
| st.success(f"β Found {len(response.data)} debate cases:") | |
| for i, case in enumerate(response.data, 1): | |
| st.write(f"**{i}.** Student: `{case.get('student_id', 'N/A')}`") | |
| st.write(f" Link: {case.get('google_doc_link', 'N/A')}") | |
| st.write(f" Description: {case.get('description', 'N/A')}") | |
| st.write(f" Created: {case.get('created_at', 'N/A')}") | |
| st.write("---") | |
| else: | |
| st.info("π No debate cases found in table") | |
| except Exception as e: | |
| st.error(f"β Error retrieving debate cases: {str(e)}") | |
| if __name__ == "__main__": | |
| add_debate_case() |