import streamlit as st import os import google.generativeai as genai st.set_page_config( page_title="Samvidhan AI", page_icon="๐", layout="wide" ) # Custom CSS st.markdown(""" """, unsafe_allow_html=True) # Header st.markdown('
๐ Samvidhan AI
', unsafe_allow_html=True) st.markdown('Constitutional Law Assistant for India
', unsafe_allow_html=True) # Safe API key handling api_key = st.secrets.get("GOOGLE_API_KEY", os.getenv("GOOGLE_API_KEY", "")) if api_key: try: genai.configure(api_key=api_key) except Exception as e: st.error(f"โ Error configuring API: {str(e)}") else: st.warning("โ ๏ธ API key not found. The analysis feature will be disabled.") def get_constitutional_analysis(scenario): """Generate constitutional analysis using Google Gemini""" if not api_key: return "โ API key not configured. Please contact the space administrator." try: model = genai.GenerativeModel('gemini-1.5-flash') prompt = f""" You are a Constitutional law expert specializing in the Constitution of India. Provide a comprehensive, factual, and unbiased analysis of the following scenario: **Scenario:** {scenario} **Please provide a detailed analysis including:** 1. **Relevant Constitutional Articles**: List specific articles with exact numbers and brief descriptions 2. **Legal Framework**: Explain how these constitutional provisions apply to this scenario 3. **Possible Interpretations**: Discuss different legal perspectives and potential outcomes 4. **Judicial Precedents**: Mention any relevant Supreme Court or High Court cases if applicable 5. **Constitutional Balance**: Explain any competing rights or principles involved 6. **Practical Implications**: What this means in real-world legal terms 7. **Areas of Uncertainty**: Any ambiguous aspects or evolving jurisprudence """ response = model.generate_content(prompt) return response.text except Exception as e: return f"โ Error generating analysis: {str(e)}" # Example scenarios examples = [ { "title": "Free Speech vs Public Order", "scenario": "A state government passes a law restricting online speech criticizing its ministers, citing maintenance of public order. Citizens argue this violates their fundamental right to free speech. Is this constitutional under Indian law?" }, { "title": "Religious Freedom in Education", "scenario": "A private Christian school refuses admission to a Muslim student, stating they only admit Christian students to maintain their religious character. The student's parents file a complaint claiming discrimination. What does the Constitution say about this?" }, { "title": "Reservation Policy Challenge", "scenario": "A general category student with 95% marks is denied admission to a medical college, while an SC category student with 70% marks gets admission under reservation. The general category student challenges this as violating equality. Is the reservation policy constitutional?" }, { "title": "Property Rights & Land Acquisition", "scenario": "The government wants to acquire private agricultural land for a highway project. The farmer refuses to sell, claiming it violates his property rights. The government proceeds with compulsory acquisition. What are the constitutional provisions here?" }, { "title": "Emergency Powers", "scenario": "During a natural disaster, a state government declares emergency and suspends all fundamental rights for 30 days, including the right to move freely and conduct business. A business owner challenges this in court. Is such action constitutionally valid?" }, { "title": "Right to Privacy vs National Security", "scenario": "The government introduces a law requiring all citizens to provide biometric data and link it to all their activities. Citizens challenge this citing right to privacy. How does the Constitution balance privacy rights with national security?" } ] # Example section st.markdown("## ๐ก Example Constitutional Scenarios") with st.expander("๐ View Example Scenarios"): for i, example in enumerate(examples, 1): st.markdown(f"**{i}. {example['title']}**") st.markdown(f"