Py.Cafe

taylorcharlton2009-ux/

taxclear-ai-uk-tax-mtd-tool

TaxClear AI – UK Tax & MTD Tool

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import streamlit as st
import google.generativeai as genai
import pycafe

# --- GET YOUR API KEY SECURELY ---
GEMINI_KEY = pycafe.get_secret("AQ.Ab8RN6Kkx20urDhlec8MMMARvTMttk3a0hoRERrBRKXwKmnXgQ", "Enter your Gemini API key to run TaxClear AI")
genai.configure(api_key=GEMINI_KEY)
model = genai.GenerativeModel("gemini-1.5-flash")

# --- STRICT UK TAX RULES ---
SYSTEM = """You are TaxClear AI – UK Landlord & Sole Trader Tax Helper.
Only use HMRC/GOV.UK rules for tax years 2025/26 to 2027/28.
Section 24: Residential mortgage interest gives a 20% tax credit, NOT a full deduction.
Compare £1,000 Property Allowance vs actual expenses – you cannot use both.
MTD ITSA: Mandatory April 2026 for income over £50,000; April 2027 for over £30,000.
Reference SA105 property pages, Rent-a-Room (£7,500 tax-free), Replacement of Domestic Items relief.
Always show: "Guidance only, not formal tax advice – verify with HMRC or an accountant."
If unsure, say so and direct to GOV.UK – do not guess."""

# --- PAGE LAYOUT ---
st.set_page_config(page_title="TaxClear AI", page_icon="🧾", layout="centered")
st.title("🧾 TaxClear AI – UK Tax & MTD Tool")
st.caption("Guidance only, not formal tax advice – verify with HMRC or an accountant.")
st.divider()

# --- CHAT SETUP ---
if "chat" not in st.session_state:
    st.session_state.chat = model.start_chat(history=[{"role":"user", "parts":[SYSTEM]}])

    # Show past messages
    for msg in st.session_state.chat.history[1:]:
        st.chat_message("user" if msg.role == "user" else "assistant").markdown(msg.parts[0].text)

        # --- NEW QUESTION ---
        if user_query := st.chat_input("Ask about MTD, Section 24, expenses, deadlines…"):
            st.chat_message("user").markdown(user_query)
                with st.spinner("Checking HMRC rules…"):
                        response = st.session_state.chat.send_message(user_query).text
                            st.chat_message("assistant").markdown(response)