Spaces:
Sleeping
Sleeping
Fix: convert amounts to numeric before formatting (handles string + native)
Browse files1234567891034515 unmodified lines21222332332425265 unmodified lines323334453536373 unmodified lines414243555644454627 unmodified lines74757690917778793 unmodified lines83848510186103878889908 unmodified lines99100101102103104105106107108109110111112124125113114115116117118"""VynFi Streamlit Template β Generate, Explore, Visualize
A ready-to-deploy Streamlit app that connects to the VynFi API,generates synthetic financial data, and renders interactive dashboards.Clone and customize for your use case.
Usage: export VYNFI_API_KEY=vf_live_... streamlit run app.py"""
import os15 unmodified lines
client = vynfi.VynFi(api_key=api_key)
# ββ Sidebar: generation config ββββββββββββββββββββββββββββββββββββββββββββββ
st.sidebar.header("Generate")
sector = st.sidebar.selectbox(5 unmodified linescompanies = st.sidebar.slider("Companies", min_value=1, max_value=20, value=3)fraud_rate = st.sidebar.slider("Fraud rate", min_value=0.0, max_value=0.20, value=0.03, step=0.01)
# NL config optionst.sidebar.divider()nl_description = st.sidebar.text_area( "Or describe what you want (Scale+)",3 unmodified lines
generate = st.sidebar.button("Generate", type="primary", use_container_width=True)
# ββ Main area ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if generate: with st.spinner("Generating..."): try:27 unmodified lines except Exception as e: st.error(f"Error: {e}")
# ββ Display results ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if "archive" in st.session_state: archive = st.session_state["archive"]
3 unmodified lines st.subheader("Journal Entries") try: entries = archive.json("journal_entries.json") # Flatten rows_flat = [] for entry in entries[:500]: # Cap for display for entry in entries[:500]: header = entry.get("header", entry) lines = entry.get("lines", [entry]) for line in lines:8 unmodified lines "credit_amount": line.get("credit_amount", 0), }) df = pd.DataFrame(rows_flat)
# Convert amounts to numeric (handles both string and native) for col in ["debit_amount", "credit_amount"]: df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0)
st.metric("Line items", f"{len(df):,}")
col1, col2 = st.columns(2) with col1: st.metric("Total debits", f"${df['debit_amount'].sum():,.2f}") with col2: fraud_count = df["is_fraud"].sum() st.metric("Fraud entries", f"{fraud_count} ({fraud_count/len(df)*100:.1f}%)") fraud_count = int(df["is_fraud"].sum()) pct = fraud_count / len(df) * 100 if len(df) > 0 else 0 st.metric("Fraud entries", f"{fraud_count} ({pct:.1f}%)")
st.dataframe(df, use_container_width=True, hide_index=True) except Exception as e:app.py+9-19