import streamlit as st import requests # Hardcoded active backend URL for your Hugging Face production environment BACKEND_URL = "https://goodgoals-natarajanreformed-backend.hf.space" # 1. Establish Ultra-Premium Page Configuration st.set_page_config( page_title="Natarajan AI — Workspace", page_icon="💎", layout="wide", initial_sidebar_state="expanded" ) # 2. Inject Custom CSS Framework (Fixes Contrast, Typography, & Layouts) st.markdown(""" """, unsafe_allow_html=True) # Initialize Session Memory States if "messages" not in st.session_state: st.session_state.messages = [] if "thread_id" not in st.session_state: st.session_state.thread_id = None if "auth_token" not in st.session_state: st.session_state.auth_token = None if "username" not in st.session_state: st.session_state.username = None # 3. Sidebar Configuration (Authentication & Status Matrix) with st.sidebar: st.markdown("
", unsafe_allow_html=True) st.markdown("### 💎 Natarajan AI") st.markdown("

Fluid Workspace v2.4

", unsafe_allow_html=True) st.markdown("---") # Context-Aware Authentication Panel if not st.session_state.auth_token: st.markdown("#### Identity Gateway") st.markdown('
Unauthenticated (401)
', unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) auth_mode = st.radio("Mode", ["Sign In", "Register"], label_visibility="collapsed") user_input = st.text_input("Username", key="auth_user", placeholder="Enter username") pass_input = st.text_input("Password", type="password", key="auth_pass", placeholder="Enter password") if st.button("Authenticate Token", use_container_width=True): endpoint = "/api/auth/register" if auth_mode == "Register" else "/api/auth/login" try: auth_resp = requests.post(f"{BACKEND_URL}{endpoint}", json={"username": user_input, "password": pass_input}) if auth_resp.status_code == 200 and "token" in auth_resp.json(): st.session_state.auth_token = auth_resp.json()["token"] st.session_state.username = user_input st.success("Identity verified.") st.rerun() else: st.error("Authentication rejected.") except Exception as e: st.error("Gateway offline.") else: # High-Contrast Fixed Telemetry View st.markdown(f"#### Welcome, **{st.session_state.username}**") st.markdown('
Security Token Verified
', unsafe_allow_html=True) st.markdown(f""" """, unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) if st.button("🔒 Revoke Token (Log Out)", use_container_width=True): st.session_state.auth_token = None st.session_state.username = None st.session_state.messages = [] st.session_state.thread_id = None st.rerun() st.markdown("---") if st.button("🔄 Initialize New Session", use_container_width=True): st.session_state.messages = [] st.session_state.thread_id = None st.rerun() # 4. Main Workspace Canvas Layout main_container = st.container() with main_container: if len(st.session_state.messages) == 0: st.markdown("

", unsafe_allow_html=True) st.markdown("

Fluid Intelligence Sanctuary

", unsafe_allow_html=True) st.markdown("

Run advanced architectural reasoning pipelines through Claude Opus 4.8 safely.

", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) col1, col2, col3 = st.columns(3) with col1: st.markdown('

⚡ Zero-Defect Code

Leverage 4.8\'s reasoning loop for generating complex production code and syntax mapping.

', unsafe_allow_html=True) with col2: st.markdown('

🧠 Deep Synthesis

Map multi-variable data tables or resolve dense algorithmic problems with ease.

', unsafe_allow_html=True) with col3: st.markdown('

🛡️ Persistent Sync

All logic trees automatically snapshot down to your decoupled Hugging Face backend matrix.

', unsafe_allow_html=True) # Custom rendered conversation streams instead of unstyled layout blocks for message in st.session_state.messages: if message["role"] == "user": st.markdown(f'
🙋‍♂️ You:
{message["content"]}
', unsafe_allow_html=True) elif message["role"] == "error": st.markdown(f'
{message["content"]}
', unsafe_allow_html=True) else: st.markdown(f'
💎 Natarajan AI:
{message["content"]}
', unsafe_allow_html=True) # 5. Interactive Chat Pipeline if prompt := st.chat_input("Prompt the system cluster..."): if not st.session_state.auth_token: st.session_state.messages.append({"role": "user", "content": prompt}) st.session_state.messages.append({ "role": "error", "content": "⚠️ Backend Gateway Interruption (401): Security Interruption. You must verify your identity in the sidebar before prompt sync is authorized." }) st.rerun() else: st.session_state.messages.append({"role": "user", "content": prompt}) st.rerun() # Handle API synchronization logic if authenticated # (This segment triggers when processing verified tokens)