# app.py import streamlit as st import requests import time import plotly.express as px import os from dotenv import load_dotenv # Load environment variables load_dotenv() # Set up Streamlit page st.set_page_config( page_title="Legal Rights Explorer", page_icon="⚖️", layout="wide", initial_sidebar_state="collapsed" ) # Custom CSS for professional styling st.markdown(""" """, unsafe_allow_html=True) # Country data with flags COUNTRIES = { "🇺🇸 United States": "US", "🇬🇧 United Kingdom": "UK", "🇨🇦 Canada": "CA", "🇦🇺 Australia": "AU", "🇮🇳 India": "IN", "🇩🇪 Germany": "DE", "🇫🇷 France": "FR", "🇯🇵 Japan": "JP", "🇧🇷 Brazil": "BR", "🇿🇦 South Africa": "ZA", "🇪🇸 Spain": "ES", "🇮🇹 Italy": "IT" } # Common legal scenarios SCENARIOS = [ "Traffic Stop by Police", "Workplace Discrimination", "Rental Housing Issues", "Medical Emergency Rights", "Consumer Protection", "Arrest or Detention", "Border Crossing", "Online Privacy", "Employment Termination", "Debt Collection", "Freedom of Speech", "Immigration Rights" ] # Simulated API function def get_legal_rights(country, scenario): """Simulate API response with country-specific legal rights""" # In a real implementation, this would call an external API # For this demo, we'll return simulated responses # Simulate API delay time.sleep(1.5) # Base rights that apply to most countries base_rights = [ "Right to remain silent", "Right to legal representation", "Right to be treated with dignity and respect", "Right to understand the charges against you", "Right to a fair and impartial process" ] # Country-specific additions country_specific = { "US": [ "Right to refuse unwarranted searches (4th Amendment)", "Right to due process (5th Amendment)", "Right to a speedy and public trial (6th Amendment)" ], "UK": [ "Right to legal advice under the Police and Criminal Evidence Act", "Right to have someone informed of your arrest", "Protection under the Human Rights Act 1998" ], "CA": [ "Right to be informed of the reason for detention (Charter of Rights)", "Right to retain and instruct counsel without delay", "Right to habeas corpus" ], "AU": [ "Right to silence during police questioning", "Right to communicate with a friend or relative", "Protection under the Australian Human Rights Commission Act" ], "IN": [ "Right to free legal aid under Article 39A of the Constitution", "Protection against self-incrimination (Article 20)", "Right to be informed of grounds for arrest (Article 22)" ] } # Scenario-specific additions scenario_specific = { "Traffic Stop by Police": [ "Right to see official identification", "Right to know the reason for the stop", "Right to refuse a search without probable cause", "Right to record the interaction" ], "Workplace Discrimination": [ "Right to a discrimination-free workplace", "Right to report without retaliation", "Right to reasonable accommodations", "Right to equal pay for equal work" ], "Medical Emergency Rights": [ "Right to emergency treatment regardless of insurance", "Right to informed consent", "Right to access medical records", "Right to privacy of health information" ], "Arrest or Detention": [ "Right to be informed of charges", "Right to contact your embassy if foreign national", "Right to humane treatment", "Right to challenge the lawfulness of detention" ] } # Combine rights based on country and scenario rights = base_rights.copy() if country in country_specific: rights.extend(country_specific[country]) for key, value in scenario_specific.items(): if key in scenario: rights.extend(value) break # Format the response response = f"## 🔍 Your Rights in {country}\n" response += f"### Situation: {scenario}\n\n" response += "Based on the laws of your selected country, you have the following rights:\n\n" for i, right in enumerate(set(rights), 1): response += f"✅ **{right}**\n\n" response += "\n**Important Notes:**\n" response += "- This information is for educational purposes only\n" response += "- Laws vary by jurisdiction and circumstances\n" response += "- Consult a qualified attorney for legal advice\n" return response # Main app def main(): # Header section st.markdown("""

Legal Rights Explorer

Know your rights in any situation, anywhere in the world

""", unsafe_allow_html=True) # Initialize session state if 'selected_country' not in st.session_state: st.session_state.selected_country = "🇺🇸 United States" if 'selected_scenario' not in st.session_state: st.session_state.selected_scenario = None # Main content columns col1, col2 = st.columns([1, 2], gap="large") with col1: st.markdown("### 🌍 Select Your Country") st.markdown("Choose your country to see jurisdiction-specific rights information") # Country selection cards for country_display in COUNTRIES.keys(): is_selected = st.session_state.selected_country == country_display card_class = "country-card selected" if is_selected else "country-card" st.markdown(f"""
{country_display.split()[0]} {country_display.split(' ', 1)[1]}
""", unsafe_allow_html=True) # Country visualization st.markdown("### 📊 Global Rights Index") countries = list(COUNTRIES.values()) awareness = [92, 89, 87, 85, 82, 88, 86, 84, 79, 81, 85, 83] # Simulated data fig = px.bar( x=countries, y=awareness, labels={'x': 'Country', 'y': 'Rights Awareness'}, color=awareness, color_continuous_scale='Blues', height=300 ) fig.update_layout( plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', margin=dict(l=0, r=0, t=30, b=0) ) st.plotly_chart(fig, use_container_width=True) # Legal resources with st.expander("📚 Legal Resources"): st.markdown(""" - [United Nations Human Rights](https://www.ohchr.org/) - [International Justice Resource Center](https://ijrcenter.org/) - [Global Legal Information Network](https://www.loc.gov/law/help/legal-info.php) - [World Legal Information Institute](https://www.worldlii.org/) """) with col2: st.markdown("### 🚨 Select a Legal Scenario") st.markdown("Choose a situation to understand your rights and protections") # Create buttons for each scenario cols = st.columns(2) for i, scenario in enumerate(SCENARIOS): with cols[i % 2]: if st.button( f"**{scenario}**", key=scenario, use_container_width=True, help=f"Click to see your rights for {scenario}" ): st.session_state.selected_scenario = scenario # Custom scenario input custom_scenario = st.text_input("**Or describe your specific situation:**", placeholder="e.g., 'Rights during home search'") if custom_scenario: st.session_state.selected_scenario = custom_scenario # Response area st.markdown("### ⚖️ Your Legal Rights") if st.session_state.selected_scenario: country_code = COUNTRIES[st.session_state.selected_country] with st.spinner(f"Analyzing your rights for {st.session_state.selected_scenario} in {country_code}..."): response = get_legal_rights( country_code, st.session_state.selected_scenario ) if response: st.markdown(f'
{response}
', unsafe_allow_html=True) else: st.error("Failed to get response. Please try again.") else: st.info("Please select a legal scenario to see your rights information") st.image("https://images.unsplash.com/photo-1589391886645-d51941baf7fb?auto=format&fit=crop&w=600&h=400", caption="Know Your Rights, Exercise Your Freedom") st.markdown("""

Why Know Your Rights?

Understanding your legal rights empowers you to:

"Knowledge of the law is the first defense against injustice."

""", unsafe_allow_html=True) # Footer st.markdown(""" """, unsafe_allow_html=True) # JavaScript for country selection st.markdown(""" """, unsafe_allow_html=True) if __name__ == "__main__": main()