awacke1 commited on
Commit
8eece5d
β€’
1 Parent(s): 4106d50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -6
app.py CHANGED
@@ -155,8 +155,89 @@ def archive_current_container(database_name, container_name, client):
155
  except Exception as e:
156
  return f"An error occurred while archiving data: {str(e)} 😒"
157
 
158
- # πŸ” Search Glossary function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  def search_glossary(query):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # πŸ•΅οΈβ€β™‚οΈ Searching the glossary for: query
161
  all_results = ""
162
  st.markdown(f"- {query}")
@@ -176,7 +257,6 @@ def search_glossary(query):
176
 
177
  #llm_model_picked Literal['mistralai/Mixtral-8x7B-Instruct-v0.1', 'mistralai/Mistral-7B-Instruct-v0.2', 'google/gemma-7b-it', 'None'] Default: "mistralai/Mistral-7B-Instruct-v0.2"
178
 
179
-
180
  client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
181
  result = client.predict(
182
  prompt=query,
@@ -184,7 +264,6 @@ def search_glossary(query):
184
  stream_outputs=True,
185
  api_name="/ask_llm"
186
  )
187
-
188
  st.write('πŸ” Run of Multi-Agent System Paper Summary Spec is Complete')
189
  st.markdown(response2)
190
 
@@ -197,9 +276,12 @@ def search_glossary(query):
197
  "mistralai/Mixtral-8x7B-Instruct-v0.1", # LLM Model Dropdown component
198
  api_name="/update_with_rag_md"
199
  )
200
- st.write('πŸ” Run of Multi-Agent System Paper References is Complete')
201
- responseall = response2 + response1[0] + response1[1]
202
- st.markdown(responseall)
 
 
 
203
  return responseall
204
 
205
  # πŸ“ Function to process text input
@@ -465,6 +547,7 @@ def main():
465
  st.error(message)
466
  except json.JSONDecodeError as e:
467
  st.error(f"Invalid JSON: {str(e)} 🚫")
 
468
  elif selected_view == 'Show as Edit and Save':
469
  # ✏️ Show as Edit and Save in columns
470
  st.markdown("#### Edit the document fields below:")
@@ -494,6 +577,7 @@ def main():
494
  st.error(message)
495
  except json.JSONDecodeError as e:
496
  st.error(f"Invalid JSON: {str(e)} 🚫")
 
497
  elif selected_view == 'Clone Document':
498
  # 🧬 Clone Document per record
499
  st.markdown("#### Clone a document:")
@@ -525,6 +609,7 @@ def main():
525
  st.error(message)
526
  except json.JSONDecodeError as e:
527
  st.error(f"Invalid JSON: {str(e)} 🚫")
 
528
  elif selected_view == 'New Record':
529
  # πŸ†• New Record
530
  st.markdown("#### Create a new document:")
@@ -544,6 +629,7 @@ def main():
544
  st.error(message)
545
  except json.JSONDecodeError as e:
546
  st.error(f"Invalid JSON: {str(e)} 🚫")
 
547
  else:
548
  st.sidebar.info("No documents found in this container. πŸ“­")
549
 
 
155
  except Exception as e:
156
  return f"An error occurred while archiving data: {str(e)} 😒"
157
 
158
+
159
+ # Helper to extract hyperlinks
160
+ def extract_hyperlinks(responses):
161
+ hyperlinks = []
162
+ for response in responses:
163
+ parsed_response = json.loads(response)
164
+ links = [value for key, value in parsed_response.items() if isinstance(value, str) and value.startswith("http")]
165
+ hyperlinks.extend(links)
166
+ return hyperlinks
167
+
168
+ # Helper to format text with line numbers
169
+ def format_with_line_numbers(text):
170
+ lines = text.splitlines()
171
+ formatted_text = '\n'.join(f"{i+1}: {line}" for i, line in enumerate(lines))
172
+ return formatted_text
173
+
174
+ # Save responses to Cosmos DB
175
+ def save_to_cosmos_db(query, response1, response2):
176
+ cosmos_container = st.session_state.get("cosmos_container")
177
+ if cosmos_container:
178
+ record = {
179
+ "query": query,
180
+ "response1": json.loads(response1),
181
+ "response2": json.loads(response2)
182
+ }
183
+ try:
184
+ cosmos_container.create_item(body=record)
185
+ st.success(f"Record saved successfully with ID: {record['id']}")
186
+ except exceptions.CosmosHttpResponseError as e:
187
+ st.error(f"Error saving record to Cosmos DB: {e}")
188
+ else:
189
+ st.error("Cosmos DB is not initialized.")
190
+
191
+
192
+ # Add dropdowns for model and database choices
193
  def search_glossary(query):
194
+ st.markdown(f"### πŸ” Search Glossary for: `{query}`")
195
+
196
+ # Dropdown for model selection
197
+ model_options = ['mistralai/Mixtral-8x7B-Instruct-v0.1', 'mistralai/Mistral-7B-Instruct-v0.2', 'google/gemma-7b-it', 'None']
198
+ model_choice = st.selectbox('🧠 Select LLM Model', options=model_options, index=1)
199
+
200
+ # Dropdown for database selection
201
+ database_options = ['Semantic Search', 'Arxiv Search - Latest - (EXPERIMENTAL)']
202
+ database_choice = st.selectbox('πŸ“š Select Database', options=database_options, index=0)
203
+
204
+ # Run Button with Emoji
205
+ if st.button("πŸš€ Run"):
206
+ # ArXiv searcher - Paper Summary & Ask LLM
207
+ client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
208
+
209
+ response1 = client.predict(
210
+ message=query,
211
+ llm_results_use=5,
212
+ database_choice=database_choice,
213
+ llm_model_picked=model_choice,
214
+ api_name="/update_with_rag_md"
215
+ )
216
+
217
+ response2 = client.predict(
218
+ prompt=query,
219
+ llm_model_picked=model_choice,
220
+ stream_outputs=True,
221
+ api_name="/ask_llm"
222
+ )
223
+
224
+ # Aggregate hyperlinks and show with emojis
225
+ hyperlinks = extract_hyperlinks([response1, response2])
226
+ st.markdown("### πŸ”— Aggregated Hyperlinks")
227
+ for link in hyperlinks:
228
+ st.markdown(f"πŸ”— [{link}]({link})")
229
+
230
+ # Show responses in a code format with line numbers
231
+ st.markdown("### πŸ“œ Response Outputs with Line Numbers")
232
+ st.code(f"Response 1: \n{format_with_line_numbers(response1)}\n\nResponse 2: \n{format_with_line_numbers(response2)}", language="json")
233
+
234
+ # Save both responses to Cosmos DB
235
+ save_to_cosmos_db(query, response1, response2)
236
+
237
+
238
+
239
+ # πŸ” Search Glossary function
240
+ def search_glossaryv1(query):
241
  # πŸ•΅οΈβ€β™‚οΈ Searching the glossary for: query
242
  all_results = ""
243
  st.markdown(f"- {query}")
 
257
 
258
  #llm_model_picked Literal['mistralai/Mixtral-8x7B-Instruct-v0.1', 'mistralai/Mistral-7B-Instruct-v0.2', 'google/gemma-7b-it', 'None'] Default: "mistralai/Mistral-7B-Instruct-v0.2"
259
 
 
260
  client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
261
  result = client.predict(
262
  prompt=query,
 
264
  stream_outputs=True,
265
  api_name="/ask_llm"
266
  )
 
267
  st.write('πŸ” Run of Multi-Agent System Paper Summary Spec is Complete')
268
  st.markdown(response2)
269
 
 
276
  "mistralai/Mixtral-8x7B-Instruct-v0.1", # LLM Model Dropdown component
277
  api_name="/update_with_rag_md"
278
  )
279
+
280
+
281
+
282
+ #st.write('πŸ” Run of Multi-Agent System Paper References is Complete')
283
+ #responseall = response2 + response1[0] + response1[1]
284
+ #st.markdown(responseall)
285
  return responseall
286
 
287
  # πŸ“ Function to process text input
 
547
  st.error(message)
548
  except json.JSONDecodeError as e:
549
  st.error(f"Invalid JSON: {str(e)} 🚫")
550
+
551
  elif selected_view == 'Show as Edit and Save':
552
  # ✏️ Show as Edit and Save in columns
553
  st.markdown("#### Edit the document fields below:")
 
577
  st.error(message)
578
  except json.JSONDecodeError as e:
579
  st.error(f"Invalid JSON: {str(e)} 🚫")
580
+
581
  elif selected_view == 'Clone Document':
582
  # 🧬 Clone Document per record
583
  st.markdown("#### Clone a document:")
 
609
  st.error(message)
610
  except json.JSONDecodeError as e:
611
  st.error(f"Invalid JSON: {str(e)} 🚫")
612
+
613
  elif selected_view == 'New Record':
614
  # πŸ†• New Record
615
  st.markdown("#### Create a new document:")
 
629
  st.error(message)
630
  except json.JSONDecodeError as e:
631
  st.error(f"Invalid JSON: {str(e)} 🚫")
632
+
633
  else:
634
  st.sidebar.info("No documents found in this container. πŸ“­")
635