Ritvik19 commited on
Commit
dd7f91e
·
verified ·
1 Parent(s): 00bc7cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -29
app.py CHANGED
@@ -8,6 +8,7 @@ import json
8
  from langchain.callbacks import get_openai_callback
9
  from langchain.chains import ConversationalRetrievalChain
10
  from langchain_openai import ChatOpenAI
 
11
 
12
  st.set_page_config(layout="wide")
13
  os.environ["OPENAI_API_KEY"] = "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"
@@ -21,6 +22,24 @@ session_state_2_llm_chat_history = lambda session_state: [
21
  ai_message_format = lambda message, references: (
22
  f"{message}\n\n---\n\n{references}" if references != "" else message
23
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
  def process_documents_wrapper(inputs):
@@ -78,13 +97,9 @@ def download_conversation_wrapper(inputs=None):
78
  ),
79
  }
80
  )
81
- st.sidebar.download_button(
82
- "Download Conversation",
83
- conversation_data,
84
- file_name="conversation_data.json",
85
- mime="application/json",
86
- )
87
  st.session_state.messages.append(("/download", "Conversation data downloaded", ""))
 
88
 
89
 
90
  def query_llm_wrapper(inputs):
@@ -120,33 +135,17 @@ def query_llm_wrapper(inputs):
120
 
121
 
122
  def boot(command_center):
123
- st.write(
124
- """
125
- # Agent Xi
126
- Hi I'm Agent Xi 📚 your AI assistant 🤖, dedicated to making your journey through machine learning research papers as insightful and interactive as possible. Whether you're diving into the latest studies or brushing up on foundational papers, I'm here to help navigate, discuss, and analyze content with you.
127
-
128
- Here's a quick guide to getting started with me:
129
-
130
- | Command | Description |
131
- |---------|-------------|
132
- | `/upload` | Upload and process documents for our conversation. |
133
- | `/index` | View an index of processed documents to easily navigate your research. |
134
- | `/cost` | Calculate the cost of our conversation, ensuring transparency in resource usage. |
135
- | `/download` | Download conversation data for your records or further analysis. |
136
-
137
- <br>
138
-
139
- Feel free to use these commands to enhance your research experience. Let's embark on this exciting journey of discovery together!
140
- """,
141
- unsafe_allow_html=True,
142
- )
143
  if "costing" not in st.session_state:
144
  st.session_state.costing = []
145
  if "messages" not in st.session_state:
146
  st.session_state.messages = []
 
147
  for message in st.session_state.messages:
148
  st.chat_message("human").write(message[0])
149
- st.chat_message("ai").write(ai_message_format(message[1], message[2]))
 
 
150
  if query := st.chat_input():
151
  st.chat_message("human").write(query)
152
  response = command_center.execute_command(query)
@@ -154,9 +153,11 @@ Feel free to use these commands to enhance your research experience. Let's embar
154
  pass
155
  elif type(response) == tuple:
156
  result, references = response
157
- st.chat_message("ai").write(ai_message_format(result, references))
 
 
158
  else:
159
- st.chat_message("ai").write(response)
160
 
161
 
162
  if __name__ == "__main__":
@@ -165,6 +166,7 @@ if __name__ == "__main__":
165
  ("/index", None, index_documents_wrapper),
166
  ("/cost", None, calculate_cost_wrapper),
167
  ("/download", None, download_conversation_wrapper),
 
168
  ]
169
  command_center = CommandCenter(
170
  default_input_type=str,
 
8
  from langchain.callbacks import get_openai_callback
9
  from langchain.chains import ConversationalRetrievalChain
10
  from langchain_openai import ChatOpenAI
11
+ import base64
12
 
13
  st.set_page_config(layout="wide")
14
  os.environ["OPENAI_API_KEY"] = "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"
 
22
  ai_message_format = lambda message, references: (
23
  f"{message}\n\n---\n\n{references}" if references != "" else message
24
  )
25
+ welcome_message = """
26
+ Hi I'm Agent Xi, your AI assistant, dedicated to making your journey through machine learning research papers as insightful and interactive as possible. Whether you're diving into the latest studies or brushing up on foundational papers, I'm here to help navigate, discuss, and analyze content with you.
27
+
28
+ Here's a quick guide to getting started with me:
29
+
30
+ | Command | Description |
31
+ |---------|-------------|
32
+ | `/upload` | Upload and process documents for our conversation. |
33
+ | `/index` | View an index of processed documents to easily navigate your research. |
34
+ | `/cost` | Calculate the cost of our conversation, ensuring transparency in resource usage. |
35
+ | `/download` | Download conversation data for your records or further analysis. |
36
+
37
+ <br>
38
+
39
+ Feel free to use these commands to enhance your research experience. Let's embark on this exciting journey of discovery together!
40
+
41
+ Use `/man` at any point of time to view this guide again.
42
+ """
43
 
44
 
45
  def process_documents_wrapper(inputs):
 
97
  ),
98
  }
99
  )
100
+ conversation_data = base64.b64encode(conversation_data.encode()).decode()
 
 
 
 
 
101
  st.session_state.messages.append(("/download", "Conversation data downloaded", ""))
102
+ return f'<a href="data:text/csv;base64,{conversation_data}" download="conversation_data.json">Download Conversation</a>'
103
 
104
 
105
  def query_llm_wrapper(inputs):
 
135
 
136
 
137
  def boot(command_center):
138
+ st.write("# Agent Xi")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  if "costing" not in st.session_state:
140
  st.session_state.costing = []
141
  if "messages" not in st.session_state:
142
  st.session_state.messages = []
143
+ st.chat_message("ai").write(welcome_message, unsafe_allow_html=True)
144
  for message in st.session_state.messages:
145
  st.chat_message("human").write(message[0])
146
+ st.chat_message("ai").write(
147
+ ai_message_format(message[1], message[2]), unsafe_allow_html=True
148
+ )
149
  if query := st.chat_input():
150
  st.chat_message("human").write(query)
151
  response = command_center.execute_command(query)
 
153
  pass
154
  elif type(response) == tuple:
155
  result, references = response
156
+ st.chat_message("ai").write(
157
+ ai_message_format(result, references), unsafe_allow_html=True
158
+ )
159
  else:
160
+ st.chat_message("ai").write(response, unsafe_allow_html=True)
161
 
162
 
163
  if __name__ == "__main__":
 
166
  ("/index", None, index_documents_wrapper),
167
  ("/cost", None, calculate_cost_wrapper),
168
  ("/download", None, download_conversation_wrapper),
169
+ ("/man", None, lambda x: welcome_message),
170
  ]
171
  command_center = CommandCenter(
172
  default_input_type=str,