Spaces:
Sleeping
Sleeping
Fix: convert amounts to numeric before formatting (handles string + native)
Browse files1234567891011121315 unmodified lines29303132333435365 unmodified lines424344454647483 unmodified lines525354555657585927 unmodified lines87888990919293943 unmodified lines98991001011021031041051068 unmodified lines115116117118119120121122123124125126127128"""VynFi Streamlit Template β Generate, Explore, VisualizeA 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 linesclient = 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 linesgenerate = st.sidebar.button("Generate", type="primary", use_container_width=True)# ββ Main area ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββif generate:with st.spinner("Generating..."):try:27 unmodified linesexcept Exception as e:st.error(f"Error: {e}")# ββ Display results ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββif "archive" in st.session_state:archive = st.session_state["archive"]3 unmodified linesst.subheader("Journal Entries")try:entries = archive.json("journal_entries.json")# Flattenrows_flat = []for entry in entries[:500]: # Cap for displayheader = 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)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}%)")st.dataframe(df, use_container_width=True, hide_index=True)except Exception as e:1234515 unmodified lines2122232425265 unmodified lines3233343536373 unmodified lines41424344454627 unmodified lines7475767778793 unmodified lines83848586878889908 unmodified lines99100101102103104105106107108109110111112113114115116117118"""VynFi Streamlit Template β Generate, Explore, Visualize"""import os15 unmodified linesclient = vynfi.VynFi(api_key=api_key)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)st.sidebar.divider()nl_description = st.sidebar.text_area("Or describe what you want (Scale+)",3 unmodified linesgenerate = st.sidebar.button("Generate", type="primary", use_container_width=True)if generate:with st.spinner("Generating..."):try:27 unmodified linesexcept Exception as e:st.error(f"Error: {e}")if "archive" in st.session_state:archive = st.session_state["archive"]3 unmodified linesst.subheader("Journal Entries")try:entries = archive.json("journal_entries.json")rows_flat = []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 = int(df["is_fraud"].sum())pct = fraud_count / len(df) * 100 if len(df) > 0 else 0st.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