Download app.py from saqib1915/CaseDiary: direct link, hf CLI and curl.
- Browser
- Download file 5.01 kB
-
https://huggingface.co/spaces/saqib1915/CaseDiary/resolve/main/app.py
- Command line
-
hf download hf://spaces/saqib1915/CaseDiary/app.py
-
curl -L -o app.py https://huggingface.co/spaces/saqib1915/CaseDiary/resolve/main/app.py
5.01 kB
| import streamlit as st | |
| import pandas as pd | |
| from datetime import datetime | |
| # Initialize session state | |
| if "cases" not in st.session_state: | |
| st.session_state["cases"] = [] | |
| if "stages" not in st.session_state: | |
| st.session_state["stages"] = ["Initial", "Hearing", "Judgment"] | |
| # Helper functions | |
| def add_case(last_date, title, judge, status, stage, next_date): | |
| st.session_state["cases"].append({ | |
| "Last Date": last_date, | |
| "Title": title, | |
| "Judge": judge, | |
| "Judge Status": status, | |
| "Stage": stage, | |
| "Next Date": next_date | |
| }) | |
| def delete_case(index): | |
| del st.session_state["cases"][index] | |
| def update_case(index, key, value): | |
| st.session_state["cases"][index][key] = value | |
| # App title | |
| st.markdown( | |
| """ | |
| <style> | |
| .app-title { | |
| font-size: 2.5rem; | |
| font-weight: bold; | |
| text-align: center; | |
| color: #2A2A2A; | |
| margin-bottom: 2rem; | |
| } | |
| .sub-header { | |
| font-size: 1.5rem; | |
| font-weight: bold; | |
| margin-bottom: 1rem; | |
| color: #333333; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| st.markdown('<div class="app-title">Lawyer\'s Case Diary</div>', unsafe_allow_html=True) | |
| # Layout setup | |
| st.write("---") | |
| col_left, col_right = st.columns([2, 3]) | |
| # Add New Case Form (Left Side) | |
| with col_left: | |
| st.markdown('<div class="sub-header">Add a New Case</div>', unsafe_allow_html=True) | |
| st.write("Fill out the details below to add a new case.") | |
| with st.form("add_case_form", clear_on_submit=True): | |
| last_date = st.date_input("Last Date", datetime.today(), label_visibility="visible") | |
| title = st.text_area("Case Title", placeholder="Enter case title here...", height=100) | |
| judge = st.text_input("Judge Name", placeholder="Enter judge name...") | |
| judge_status = st.radio("Judge Status", ["Yes", "No"], horizontal=True) | |
| stage = st.selectbox("Stage", st.session_state["stages"] + ["Add New Stage"]) | |
| if stage == "Add New Stage": | |
| new_stage = st.text_input("New Stage", placeholder="Enter a new stage...") | |
| if new_stage and st.form_submit_button("Add Stage"): | |
| st.session_state["stages"].append(new_stage) | |
| stage = new_stage | |
| next_date = st.date_input("Next Date", datetime.today(), label_visibility="visible") | |
| if st.form_submit_button("Add Case", type="primary"): | |
| add_case( | |
| last_date.strftime("%d/%m/%Y"), | |
| title, | |
| judge, | |
| judge_status, | |
| stage, | |
| next_date.strftime("%d/%m/%Y") | |
| ) | |
| st.success("Case added successfully!") | |
| # Display Cases (Right Side) | |
| with col_right: | |
| st.markdown('<div class="sub-header">View Cases</div>', unsafe_allow_html=True) | |
| selected_date = st.date_input("Select Date to View Cases", datetime.today(), label_visibility="visible") | |
| selected_date_str = selected_date.strftime("%d/%m/%Y") | |
| cases_df = pd.DataFrame(st.session_state["cases"]) | |
| filtered_cases = cases_df[cases_df["Next Date"] == selected_date_str] if not cases_df.empty else pd.DataFrame() | |
| if not filtered_cases.empty: | |
| st.write(f"Cases scheduled for **{selected_date_str}**:") | |
| for index, case in filtered_cases.iterrows(): | |
| with st.expander(f"Case: {case['Title']}"): | |
| col1, col2, col3 = st.columns([2, 2, 1]) | |
| with col1: | |
| st.markdown(f"**Last Date:** {case['Last Date']}") | |
| st.markdown(f"**Judge:** {case['Judge']}") | |
| st.markdown(f"**Stage:** {case['Stage']}") | |
| with col2: | |
| st.markdown(f"**Judge Status:** {case['Judge Status']}") | |
| next_date = st.date_input( | |
| "Next Date", | |
| datetime.strptime(case["Next Date"], "%d/%m/%Y"), | |
| key=f"next_date_{index}" | |
| ) | |
| if st.button("Save Date", key=f"save_date_{index}"): | |
| update_case(index, "Next Date", next_date.strftime("%d/%m/%Y")) | |
| st.success("Next date updated.") | |
| with col3: | |
| if st.button("Delete Case", key=f"delete_{index}"): | |
| delete_case(index) | |
| st.warning("Case deleted successfully.") | |
| else: | |
| st.info(f"No cases scheduled for {selected_date_str}.") | |
| # Style Customization | |
| st.markdown( | |
| """ | |
| <style> | |
| .stButton>button { | |
| background-color: #4CAF50 !important; | |
| color: white !important; | |
| border-radius: 8px; | |
| padding: 8px 15px; | |
| font-size: 1rem; | |
| font-weight: bold; | |
| } | |
| .stTextInput, .stTextArea, .stDateInput, .stSelectbox, .stRadio { | |
| font-size: 1rem; | |
| } | |
| .stExpander { | |
| background-color: #f8f9fa !important; | |
| border-radius: 8px; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |