bhavika24 commited on
Commit
5ff4451
·
verified ·
1 Parent(s): 81dac89

Upload UI.py

Browse files
Files changed (1) hide show
  1. UI.py +22 -17
UI.py CHANGED
@@ -44,16 +44,6 @@ if user_input:
44
  with st.spinner("Thinking..."):
45
  try:
46
  result = process_question(user_input)
47
-
48
- # ✅ Store transcript safely
49
- st.session_state.transcript.append({
50
- "timestamp": datetime.utcnow().isoformat(),
51
- "question": user_input,
52
- "sql": result.get("sql"),
53
- "result_preview": result.get("data", [])[:10],
54
- "error": result.get("message") if result.get("status") != "ok" else None
55
- })
56
-
57
  except Exception as e:
58
  result = {
59
  "status": "error",
@@ -93,7 +83,21 @@ if user_input:
93
  else:
94
  reply = f"❌ {result.get('message', 'Something went wrong')}"
95
 
96
- # Show assistant message
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  st.session_state.messages.append(
98
  {"role": "assistant", "content": reply}
99
  )
@@ -102,7 +106,7 @@ if user_input:
102
  st.markdown(reply, unsafe_allow_html=True)
103
 
104
  # =========================
105
- # DOWNLOAD TRANSCRIPT (BOTTOM ONLY)
106
  # =========================
107
  def download_transcript_txt():
108
  lines = []
@@ -111,18 +115,19 @@ def download_transcript_txt():
111
  lines.append(f"Time: {entry['timestamp']}")
112
  lines.append(f"Question: {entry['question']}")
113
 
114
- if entry.get("sql"):
115
- lines.append(f"SQL: {entry['sql']}")
 
116
 
117
- if entry.get("result_preview"):
118
- lines.append(f"Result Preview: {entry['result_preview']}")
119
 
120
  if entry.get("error"):
121
  lines.append(f"Error: {entry['error']}")
122
 
123
  return "\n".join(lines)
124
 
125
-
126
  if st.session_state.transcript:
127
  st.divider()
128
  st.download_button(
 
44
  with st.spinner("Thinking..."):
45
  try:
46
  result = process_question(user_input)
 
 
 
 
 
 
 
 
 
 
47
  except Exception as e:
48
  result = {
49
  "status": "error",
 
83
  else:
84
  reply = f"❌ {result.get('message', 'Something went wrong')}"
85
 
86
+ # =========================
87
+ # SAVE TRANSCRIPT ✅ FIXED
88
+ # =========================
89
+ st.session_state.transcript.append({
90
+ "timestamp": datetime.utcnow().isoformat(),
91
+ "question": user_input,
92
+ "reply": reply, # ✅ THIS WAS MISSING
93
+ "sql": result.get("sql"),
94
+ "result_preview": result.get("data", [])[:10],
95
+ "error": result.get("message") if result.get("status") != "ok" else None
96
+ })
97
+
98
+ # =========================
99
+ # SHOW ASSISTANT MESSAGE
100
+ # =========================
101
  st.session_state.messages.append(
102
  {"role": "assistant", "content": reply}
103
  )
 
106
  st.markdown(reply, unsafe_allow_html=True)
107
 
108
  # =========================
109
+ # DOWNLOAD TRANSCRIPT
110
  # =========================
111
  def download_transcript_txt():
112
  lines = []
 
115
  lines.append(f"Time: {entry['timestamp']}")
116
  lines.append(f"Question: {entry['question']}")
117
 
118
+ if entry.get("reply"):
119
+ lines.append("Reply:")
120
+ lines.append(entry["reply"])
121
 
122
+ if entry.get("sql"):
123
+ lines.append(f"SQL:\n{entry['sql']}")
124
 
125
  if entry.get("error"):
126
  lines.append(f"Error: {entry['error']}")
127
 
128
  return "\n".join(lines)
129
 
130
+ # Show download button only if data exists
131
  if st.session_state.transcript:
132
  st.divider()
133
  st.download_button(