rairo commited on
Commit
3beea9b
·
verified ·
1 Parent(s): 7eb96e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -92,6 +92,22 @@ def create_knowledge_base(data):
92
 
93
  return qa_chain
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  def main():
96
  st.sidebar.title("Quantilytix Grant Scraper")
97
  st.sidebar.image("logoqb.jpeg", use_container_width=True)
@@ -129,6 +145,8 @@ def main():
129
  b64 = base64.b64encode(csv_data).decode()
130
  download_link = f"<a href='data:application/vnd.ms-excel;base64,{b64}' download='grants.csv'>Download CSV</a>"
131
  st.sidebar.markdown(download_link, unsafe_allow_html=True)
 
 
132
  elif selected_format == "Excel":
133
  excel_data = convert_to_excel(result)
134
  b64 = base64.b64encode(excel_data).decode()
@@ -137,13 +155,15 @@ def main():
137
 
138
  st.dataframe(result['grants'])
139
 
 
 
140
  if st.sidebar.button("Load as Knowledge Base"):
141
  st.session_state.qa_chain = create_knowledge_base(result)
142
  st.session_state.chat_interface_active = True
143
 
144
  if "chat_interface_active" in st.session_state and st.session_state.chat_interface_active:
145
- st.image("logoqb.jpeg", use_container_width=True)
146
- st.heading("Chat Interface Loaded. Start asking questions about the grants!")
147
 
148
  query = st.text_input("Ask a question about the grants:", key="chat_input")
149
  if query:
 
92
 
93
  return qa_chain
94
 
95
+ def get_shareable_link(file_data, file_name, file_type):
96
+ """
97
+ Generates a shareable link for the file using a base64 data URL.
98
+
99
+ Args:
100
+ file_data: The file data in bytes.
101
+ file_name: The name of the file.
102
+ file_type: The MIME type of the file (e.g., 'text/csv', 'application/vnd.ms-excel').
103
+
104
+ Returns:
105
+ A base64-encoded data URL for the file.
106
+ """
107
+ b64 = base64.b64encode(file_data).decode()
108
+ return f"data:{file_type};base64,{b64}"
109
+
110
+
111
  def main():
112
  st.sidebar.title("Quantilytix Grant Scraper")
113
  st.sidebar.image("logoqb.jpeg", use_container_width=True)
 
145
  b64 = base64.b64encode(csv_data).decode()
146
  download_link = f"<a href='data:application/vnd.ms-excel;base64,{b64}' download='grants.csv'>Download CSV</a>"
147
  st.sidebar.markdown(download_link, unsafe_allow_html=True)
148
+ shareable_link = get_shareable_link(result, file_name, file_type)
149
+
150
  elif selected_format == "Excel":
151
  excel_data = convert_to_excel(result)
152
  b64 = base64.b64encode(excel_data).decode()
 
155
 
156
  st.dataframe(result['grants'])
157
 
158
+
159
+
160
  if st.sidebar.button("Load as Knowledge Base"):
161
  st.session_state.qa_chain = create_knowledge_base(result)
162
  st.session_state.chat_interface_active = True
163
 
164
  if "chat_interface_active" in st.session_state and st.session_state.chat_interface_active:
165
+ st.image("logoqb.jpeg", width=100, height=100)
166
+ st.header("Chat Interface Loaded. Start asking questions about the grants!")
167
 
168
  query = st.text_input("Ask a question about the grants:", key="chat_input")
169
  if query: