Ritvik19 commited on
Commit
b05ff4a
·
verified ·
1 Parent(s): d2b4a56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  import re
4
  from pathlib import Path
5
  from statistics import median
6
-
7
  import pandas as pd
8
  import streamlit as st
9
  from bs4 import BeautifulSoup
@@ -213,6 +213,7 @@ def boot():
213
  st.session_state.costing = []
214
  if "messages" not in st.session_state:
215
  st.session_state.messages = []
 
216
  for message in st.session_state.messages:
217
  st.chat_message("human").write(message[0])
218
  st.chat_message("ai").write(message[1])
@@ -222,6 +223,7 @@ def boot():
222
  sorted_references = sorted([ref.metadata["chunk_id"] for ref in references])
223
  references_str = " ".join([f"[{ref}]" for ref in sorted_references])
224
  st.chat_message("ai").write(response + "\n\n---\nReferences:" + references_str)
 
225
  st.session_state.costing.append(
226
  {
227
  "prompt tokens": stats.prompt_tokens,
@@ -232,6 +234,16 @@ def boot():
232
  stats_df = pd.DataFrame(st.session_state.costing)
233
  stats_df.loc["total"] = stats_df.sum()
234
  st.sidebar.write(stats_df)
 
 
 
 
 
 
 
 
 
 
235
 
236
 
237
  if __name__ == "__main__":
 
3
  import re
4
  from pathlib import Path
5
  from statistics import median
6
+ import json
7
  import pandas as pd
8
  import streamlit as st
9
  from bs4 import BeautifulSoup
 
213
  st.session_state.costing = []
214
  if "messages" not in st.session_state:
215
  st.session_state.messages = []
216
+
217
  for message in st.session_state.messages:
218
  st.chat_message("human").write(message[0])
219
  st.chat_message("ai").write(message[1])
 
223
  sorted_references = sorted([ref.metadata["chunk_id"] for ref in references])
224
  references_str = " ".join([f"[{ref}]" for ref in sorted_references])
225
  st.chat_message("ai").write(response + "\n\n---\nReferences:" + references_str)
226
+
227
  st.session_state.costing.append(
228
  {
229
  "prompt tokens": stats.prompt_tokens,
 
234
  stats_df = pd.DataFrame(st.session_state.costing)
235
  stats_df.loc["total"] = stats_df.sum()
236
  st.sidebar.write(stats_df)
237
+ st.sidebar.download_button(
238
+ "Download Conversation",
239
+ json.dumps(
240
+ [
241
+ {"human": message[0], "ai": message[1]}
242
+ for message in st.session_state.messages
243
+ ]
244
+ ),
245
+ "conversation.json",
246
+ )
247
 
248
 
249
  if __name__ == "__main__":