Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# --- FIX v2: logger dedupe + run-once guards (26-Sep-2025) ---
|
| 2 |
import os, sys, logging
|
| 3 |
import os as _olist_os
|
|
@@ -4053,49 +4063,50 @@ def render_chat_output(out):
|
|
| 4053 |
|
| 4054 |
if card.get("error"):
|
| 4055 |
st.error(card["error"])
|
| 4056 |
-
else:
|
| 4057 |
-
|
| 4058 |
-
|
| 4059 |
-
|
| 4060 |
-
|
| 4061 |
-
|
| 4062 |
-
|
| 4063 |
-
|
| 4064 |
-
|
| 4065 |
-
|
| 4066 |
-
|
| 4067 |
-
|
| 4068 |
-
|
| 4069 |
-
|
| 4070 |
-
|
| 4071 |
-
|
| 4072 |
-
|
| 4073 |
-
|
| 4074 |
-
|
| 4075 |
-
|
| 4076 |
-
|
| 4077 |
-
|
| 4078 |
-
|
| 4079 |
-
|
| 4080 |
-
|
| 4081 |
-
|
| 4082 |
-
|
| 4083 |
-
|
| 4084 |
-
|
| 4085 |
-
|
| 4086 |
-
|
| 4087 |
-
|
| 4088 |
-
|
| 4089 |
-
|
| 4090 |
-
|
| 4091 |
-
|
| 4092 |
-
|
| 4093 |
-
|
| 4094 |
-
|
| 4095 |
-
|
| 4096 |
-
|
| 4097 |
-
|
| 4098 |
-
|
|
|
|
| 4099 |
|
| 4100 |
def _apply_preview_limit(sql: str, limit: int = 10) -> str:
|
| 4101 |
"""
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
try:
|
| 3 |
+
import pandas as pd # noqa: F401
|
| 4 |
+
except Exception:
|
| 5 |
+
pd = None
|
| 6 |
+
try:
|
| 7 |
+
import streamlit as st # noqa: F401
|
| 8 |
+
except Exception:
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
# --- FIX v2: logger dedupe + run-once guards (26-Sep-2025) ---
|
| 12 |
import os, sys, logging
|
| 13 |
import os as _olist_os
|
|
|
|
| 4063 |
|
| 4064 |
if card.get("error"):
|
| 4065 |
st.error(card["error"])
|
| 4066 |
+
else:
|
| 4067 |
+
|
| 4068 |
+
df_to_show = card.get("df", None)
|
| 4069 |
+
if isinstance(df_to_show, pd.DataFrame):
|
| 4070 |
+
if card.get("limit_enforced"):
|
| 4071 |
+
st.markdown(
|
| 4072 |
+
'<div class="oa-note">For performance, results are limited to <b>50</b> rows. '
|
| 4073 |
+
'Include the word <b>“All”</b> in your question to bypass this cap (may be slower).</div>',
|
| 4074 |
+
unsafe_allow_html=True
|
| 4075 |
+
)
|
| 4076 |
+
if df_to_show.empty:
|
| 4077 |
+
st.info("No rows returned.")
|
| 4078 |
+
else:
|
| 4079 |
+
_role = (st.session_state.get("auth") or {}).get("role", "").lower()
|
| 4080 |
+
if _role == "admin":
|
| 4081 |
+
cfg = _infer_columns_for_chart(df_to_show)
|
| 4082 |
+
if cfg:
|
| 4083 |
+
c_tbl, c_plt = st.columns(2, gap="large")
|
| 4084 |
+
with c_tbl:
|
| 4085 |
+
_call_render_df(df_to_show, key_prefix=f"q{i}", page_size=10)
|
| 4086 |
+
with c_plt:
|
| 4087 |
+
_render_chart_matplotlib(cfg, df_to_show)
|
| 4088 |
+
else:
|
| 4089 |
+
_call_render_df(df_to_show, key_prefix=f"q{i}", page_size=10)
|
| 4090 |
+
else:
|
| 4091 |
+
_call_render_df(df_to_show, key_prefix=f"q{i}", page_size=10)
|
| 4092 |
+
else:
|
| 4093 |
+
st.info("No tabular result to display.")
|
| 4094 |
+
def render_df_with_pagination(df: pd.DataFrame, key_prefix: str, page_size: int = 10):
|
| 4095 |
+
total = len(df)
|
| 4096 |
+
if total <= page_size:
|
| 4097 |
+
st.dataframe(df, use_container_width=True)
|
| 4098 |
+
st.caption(f"Showing 1–{total} of {total} rows.")
|
| 4099 |
+
return
|
| 4100 |
+
total_pages = math.ceil(total / page_size)
|
| 4101 |
+
page = st.number_input(
|
| 4102 |
+
"Page",
|
| 4103 |
+
min_value=1, max_value=total_pages, value=1, step=1,
|
| 4104 |
+
key=f"{key_prefix}_page"
|
| 4105 |
+
)
|
| 4106 |
+
start = (page - 1) * page_size
|
| 4107 |
+
end = min(start + page_size, total)
|
| 4108 |
+
st.dataframe(df.iloc[start:end], use_container_width=True)
|
| 4109 |
+
st.caption(f"Showing rows {start+1}–{end} of {total} (page {page}/{total_pages}).")
|
| 4110 |
|
| 4111 |
def _apply_preview_limit(sql: str, limit: int = 10) -> str:
|
| 4112 |
"""
|