Spaces:
Build error
Build error
| import streamlit as st | |
| # Initialize session state for gold price | |
| if "gold_price" not in st.session_state: | |
| st.session_state.gold_price = 6500.0 # Default gold price (float) | |
| # Tabs | |
| tab1, tab2 = st.tabs(["Zakat Calculator", "Current Gold Price"]) | |
| # Current Gold Price Tab | |
| with tab2: | |
| st.title("Current Gold Price") | |
| new_gold_price = st.number_input("Enter Current Gold Price (PKR per gram):", value=st.session_state.gold_price, min_value=0.0) | |
| if st.button("Update Gold Price"): | |
| st.session_state.gold_price = new_gold_price | |
| st.success("Gold price updated!") | |
| st.write(f"Current Gold Price: {st.session_state.gold_price:.2f} PKR per gram") | |
| st.write("Note: Please ensure the price is accurate.") | |
| # Zakat Calculator Tab | |
| with tab1: | |
| st.title("Zakat Calculator") | |
| # Input fields | |
| gold_grams = st.number_input("Gold (grams):", min_value=0.0, value=0.0) | |
| silver_grams = st.number_input("Silver (grams):", min_value=0.0, value=0.0) | |
| cash = st.number_input("Cash (currency amount):", min_value=0.0, value=0.0) | |
| business_assets = st.number_input("Business Assets (currency amount):", min_value=0.0, value=0.0) | |
| receivables = st.number_input("Receivables (currency amount):", min_value=0.0, value=0.0) | |
| # Gold and Silver prices | |
| gold_price_per_gram = st.session_state.gold_price | |
| silver_price_per_gram = 80.0 # Example price (Pakistani Rupees) - float | |
| # Calculate total wealth | |
| total_wealth = ( | |
| (gold_grams * gold_price_per_gram) | |
| + (silver_grams * silver_price_per_gram) | |
| + cash | |
| + business_assets | |
| + receivables | |
| ) | |
| # Nisab (threshold) - Example value, you should use the current Nisab. | |
| nisab = 179689.0 # Example Nisab value in Pakistani Rupees (float) | |
| # Calculate Zakat | |
| if total_wealth >= nisab: | |
| zakat = total_wealth * 0.025 # 2.5% Zakat | |
| st.success(f"Your total wealth is: {total_wealth:.2f} PKR") | |
| st.success(f"Zakat payable: {zakat:.2f} PKR") | |
| else: | |
| st.warning(f"Your total wealth ({total_wealth:.2f} PKR) is below the Nisab ({nisab:.2f} PKR). No Zakat is due.") |