code: import streamlit as st
  import pandas as pd
  import json
  import requests
  from pathlib import Path
  from datetime import datetime
  from jinja2 import Template
  import lancedb
  import sqlite3
  from services.lancedb_notes import IndexDocumentsNotes
  from services.auto_research import AutoResearch
  
  st.set_page_config(layout='wide',
                     page_title='AutoResearch')
  
  notes_folder = Path('data/notes')
  collections_folder = Path('data/collections')
  tmp_folder = Path('data/tmp')
  config_folder = Path('data/config')
  with open(config_folder.joinpath('prompt_templates.json'), 'r') as f:
      prompt_options = json.load(f)
  
  
  index_folder = Path('indexes')
  sqlite_location = Path('data/indexes/documents.sqlite')
  
  lance_index = lancedb.connect(index_folder)
  available_indexes = lance_index.table_names()
  index_to_search = st.selectbox(label='Available Indexes', options=available_indexes)
  
  query = st.text_input(label="What do you want to search?", value='')
  
  
  @st.cache_data
  def remote_search(query, collection_name):
      results = requests.post('http://localhost:8000/hybrid',
                              json={'query':query, 'collection_name':collection_name,
                                    'top_k':50, 'fts_weight':0.5, 'vec_weight':1-0.5})
  
      result_data, available_fields = results.json()
      available_fields = set(available_fields)
      new_fields = set()
      for result in result_data:
          if 'metadata' in result and len(result['metadata']) > 0:
              metadata = json.loads(result['metadata'])
              result.update(metadata)
              new_fields.update(metadata.keys())
              del result['metadata']
  
      return result_data
  
  if 'results_to_save' not in st.session_state:
      st.session_state['results_to_save'] = dict()
  def add_result_to_save(result):
      note_hash = hash(str(result))
      st.write(st.session_state['results_to_save'].keys())
      if note_hash not in st.session_state['results_to_save']:
          st.session_state['results_to_save'][note_hash] = result
      else:
          del st.session_state['results_to_save'][note_hash]
  
  
  
  if query:
      st.markdown(f"## {query}")
  
      auto_search = AutoResearch(objective=query, collection_name='trump')
      report_results = auto_search.research_question(query)
      # st.write(report_results)
  
      for task_idx in range(len(report_results)):
          task_description = report_results[str(task_idx + 1)]['task']
          task_result = report_results[str(task_idx + 1)]['results']
          # st.json(task_result)
          st.markdown(f"### Task {task_idx + 1}: {task_description['task']}")
          st.markdown(f"**Research Actions**: {task_description['actions']}")
          st.markdown(f"**Expected Outcomes**: {task_description['expected_outcomes']}")
          st.markdown(f"**Considerations**: {task_description['considerations']}")
          st.write()
          st.markdown(f"### Full Summary:\n{task_result['final_summary']}")
          st.markdown(f"### Summarized Summary:\n{task_result['summarized_summary']}")
          st.divider()
          for query_idx, sub_query in enumerate(task_result['internet_queries']):
              with st.expander(f"Expand for sub query: {sub_query}"):
                  st.markdown(f"### Subquery: {sub_query}")
                  # st.json(task_result['queries'])
                  query_results = task_result['queries'][query_idx]
                  st.markdown("#### Summary")
                  st.markdown(query_results['sub_summary'])
                  st.divider()
                  for _article in query_results['article_objects']:
                      st.markdown(f"**Title: {_article['title']}** ---  **UUID: {_article['uuid']}**")
                      st.markdown("**Text**")
                      _text = _article['text'].replace('\n','\n\n')
                      st.markdown(f"{_text}")
                      st.divider()
      #
      # for index, result in enumerate(query_results):
      #     # st.write(result)
      #     st.markdown(f"**:blue[{result['title']}]**")
      #     st.markdown(f"*:blue[Score: {round(result['score'], 3)}]*")
      #     with st.container():
      #         st.write(f"{' '.join(result['text'].split(' ')[:100])}.....")
      #         with st.expander('See Full Text and Details'):
      #             full_text, quick_annotate = st.columns([4,1])
      #             with full_text:
      #                 st.markdown('**Text:**')
      #                 st.markdown(result['text'])
              # save_to_collection = st.toggle('Save to collection',key=f'toggle_{index}',
              #                                on_change=add_result_to_save, args=(result, ))
              st.divider()
  
  
apis: lancedb.connect
extract_api: [((288, 348), 'streamlit.set_page_config', 'st.set_page_config', ([], {'layout': '"""wide"""', 'page_title': '"""AutoResearch"""'}), "(layout='wide', page_title='AutoResearch')\n", (306, 348), True, 'import streamlit as st\n'), ((384, 402), 'pathlib.Path', 'Path', (['"""data/notes"""'], {}), "('data/notes')\n", (388, 402), False, 'from pathlib import Path\n'), ((424, 448), 'pathlib.Path', 'Path', (['"""data/collections"""'], {}), "('data/collections')\n", (428, 448), False, 'from pathlib import Path\n'), ((462, 478), 'pathlib.Path', 'Path', (['"""data/tmp"""'], {}), "('data/tmp')\n", (466, 478), False, 'from pathlib import Path\n'), ((495, 514), 'pathlib.Path', 'Path', (['"""data/config"""'], {}), "('data/config')\n", (499, 514), False, 'from pathlib import Path\n'), ((636, 651), 'pathlib.Path', 'Path', (['"""indexes"""'], {}), "('indexes')\n", (640, 651), False, 'from pathlib import Path\n'), ((670, 707), 'pathlib.Path', 'Path', (['"""data/indexes/documents.sqlite"""'], {}), "('data/indexes/documents.sqlite')\n", (674, 707), False, 'from pathlib import Path\n'), ((723, 752), 'lancedb.connect', 'lancedb.connect', (['index_folder'], {}), '(index_folder)\n', (738, 752), False, 'import lancedb\n'), ((817, 883), 'streamlit.selectbox', 'st.selectbox', ([], {'label': '"""Available Indexes"""', 'options': 'available_indexes'}), "(label='Available Indexes', options=available_indexes)\n", (829, 883), True, 'import streamlit as st\n'), ((893, 953), 'streamlit.text_input', 'st.text_input', ([], {'label': '"""What do you want to search?"""', 'value': '""""""'}), "(label='What do you want to search?', value='')\n", (906, 953), True, 'import streamlit as st\n'), ((606, 618), 'json.load', 'json.load', (['f'], {}), '(f)\n', (615, 618), False, 'import json\n'), ((1028, 1195), 'requests.post', 'requests.post', (['"""http://localhost:8000/hybrid"""'], {'json': "{'query': query, 'collection_name': collection_name, 'top_k': 50,\n    'fts_weight': 0.5, 'vec_weight': 1 - 0.5}"}), "('http://localhost:8000/hybrid', json={'query': query,\n    'collection_name': collection_name, 'top_k': 50, 'fts_weight': 0.5,\n    'vec_weight': 1 - 0.5})\n", (1041, 1195), False, 'import requests\n'), ((2085, 2111), 'streamlit.markdown', 'st.markdown', (['f"""## {query}"""'], {}), "(f'## {query}')\n", (2096, 2111), True, 'import streamlit as st\n'), ((2131, 2185), 'services.auto_research.AutoResearch', 'AutoResearch', ([], {'objective': 'query', 'collection_name': '"""trump"""'}), "(objective=query, collection_name='trump')\n", (2143, 2185), False, 'from services.auto_research import AutoResearch\n'), ((2499, 2566), 'streamlit.markdown', 'st.markdown', (['f"""### Task {task_idx + 1}: {task_description[\'task\']}"""'], {}), '(f"### Task {task_idx + 1}: {task_description[\'task\']}")\n', (2510, 2566), True, 'import streamlit as st\n'), ((2575, 2642), 'streamlit.markdown', 'st.markdown', (['f"""**Research Actions**: {task_description[\'actions\']}"""'], {}), '(f"**Research Actions**: {task_description[\'actions\']}")\n', (2586, 2642), True, 'import streamlit as st\n'), ((2651, 2729), 'streamlit.markdown', 'st.markdown', (['f"""**Expected Outcomes**: {task_description[\'expected_outcomes\']}"""'], {}), '(f"**Expected Outcomes**: {task_description[\'expected_outcomes\']}")\n', (2662, 2729), True, 'import streamlit as st\n'), ((2738, 2810), 'streamlit.markdown', 'st.markdown', (['f"""**Considerations**: {task_description[\'considerations\']}"""'], {}), '(f"**Considerations**: {task_description[\'considerations\']}")\n', (2749, 2810), True, 'import streamlit as st\n'), ((2819, 2829), 'streamlit.write', 'st.write', ([], {}), '()\n', (2827, 2829), True, 'import streamlit as st\n'), ((2838, 2906), 'streamlit.markdown', 'st.markdown', (['f"""### Full Summary:\n{task_result[\'final_summary\']}"""'], {}), '(f"""### Full Summary:\n{task_result[\'final_summary\']}""")\n', (2849, 2906), True, 'import streamlit as st\n'), ((2912, 2991), 'streamlit.markdown', 'st.markdown', (['f"""### Summarized Summary:\n{task_result[\'summarized_summary\']}"""'], {}), '(f"""### Summarized Summary:\n{task_result[\'summarized_summary\']}""")\n', (2923, 2991), True, 'import streamlit as st\n'), ((2997, 3009), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (3007, 3009), True, 'import streamlit as st\n'), ((1482, 1512), 'json.loads', 'json.loads', (["result['metadata']"], {}), "(result['metadata'])\n", (1492, 1512), False, 'import json\n'), ((4586, 4598), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (4596, 4598), True, 'import streamlit as st\n'), ((3107, 3156), 'streamlit.expander', 'st.expander', (['f"""Expand for sub query: {sub_query}"""'], {}), "(f'Expand for sub query: {sub_query}')\n", (3118, 3156), True, 'import streamlit as st\n'), ((3174, 3215), 'streamlit.markdown', 'st.markdown', (['f"""### Subquery: {sub_query}"""'], {}), "(f'### Subquery: {sub_query}')\n", (3185, 3215), True, 'import streamlit as st\n'), ((3348, 3375), 'streamlit.markdown', 'st.markdown', (['"""#### Summary"""'], {}), "('#### Summary')\n", (3359, 3375), True, 'import streamlit as st\n'), ((3392, 3433), 'streamlit.markdown', 'st.markdown', (["query_results['sub_summary']"], {}), "(query_results['sub_summary'])\n", (3403, 3433), True, 'import streamlit as st\n'), ((3450, 3462), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (3460, 3462), True, 'import streamlit as st\n'), ((3549, 3634), 'streamlit.markdown', 'st.markdown', (['f"""**Title: {_article[\'title\']}** ---  **UUID: {_article[\'uuid\']}**"""'], {}), '(f"**Title: {_article[\'title\']}** ---  **UUID: {_article[\'uuid\']}**"\n    )\n', (3560, 3634), True, 'import streamlit as st\n'), ((3650, 3673), 'streamlit.markdown', 'st.markdown', (['"""**Text**"""'], {}), "('**Text**')\n", (3661, 3673), True, 'import streamlit as st\n'), ((3760, 3783), 'streamlit.markdown', 'st.markdown', (['f"""{_text}"""'], {}), "(f'{_text}')\n", (3771, 3783), True, 'import streamlit as st\n'), ((3804, 3816), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (3814, 3816), True, 'import streamlit as st\n')]