code: from dotenv import load_dotenv
  import os 
  import streamlit as st
  import pandas as pd
  from llama_index.core.query_engine import PandasQueryEngine 
  from llama_index.core.tools import QueryEngineTool, ToolMetadata
  from llama_index.core.agent import ReActAgent
  from llama_index.llms.openai import OpenAI
  from prompts import new_prompt, instruction_str, context
  from note_engine import note_engine
  from pdf import combined_engine
  from pdf import get_index as pdf_get_index
  load_dotenv()
  
  population_path = os.path.join("data", "population.csv")
  population_df = pd.read_csv(population_path)
  
  population_query_engine = PandasQueryEngine(
      df=population_df, verbose=True, instruction_str=instruction_str
      )
  population_query_engine.update_prompts({"pandas_prompt" : new_prompt})
  
  tools = [
      note_engine,
      QueryEngineTool(
          query_engine=population_query_engine,
          metadata=ToolMetadata(
              name="population_query_engine",
              description="This gives information at the world population and demographic",
          ),
      ),
      # QueryEngineTool(
      #     query_engine=malaysia_engine,
      #     metadata=ToolMetadata(
      #         name="malaysia_data",
      #         description="This gives details information about Malaysia country",
      #     ),
      # ),
          QueryEngineTool(
          query_engine=combined_engine,
          metadata=ToolMetadata(
              name="combined_data",
              description="This gives information from multiple files",
          ),
      ),
  ]
  
  
  llm = OpenAI(model="gpt-3.5-turbo-0613")
  agent = ReActAgent.from_tools(tools, llm=llm, verbose=True, context=context)
  
  # while (prompt := input("Enter a prompt (q to quit): ")) != "q":
  #     result = agent.query(prompt)
  #     print(result)
  
  file_paths = []
  
  # File uploader in the sidebar
  with st.sidebar:
      st.header("Upload PDF file")
      file = st.file_uploader("", type=["pdf"])
  
      if file:
          file_path = os.path.join("data", file.name)
          
          # Save the uploaded file
          with open(file_path, "wb") as f:
              f.write(file.getvalue())
          
          # Display confirmation message
          st.success(f"File uploaded successfully: {file.name}")
  
          # Add the uploaded file path to the list of file paths
          file_paths.append(file_path)
  
  # Check if there are any uploaded files
  if file_paths:
      # Get combined index for uploaded files
      combined_index = pdf_get_index(file_paths, 'combined_index')
      combined_engine = combined_index.as_query_engine()
  
      # Add QueryEngineTool for combined data
      tools.append(
          QueryEngineTool(
              query_engine=combined_engine,
              metadata=ToolMetadata(
                  name="combined_data",
                  description="This gives information from multiple files",
              ),
          )
      )
  
  
  st.title("AgentAI - RAG")
  
  user_input = st.text_input("Enter a prompt:")
  if user_input:
      if user_input.lower() == 'q':
          st.stop()
      else:
          result = agent.query(user_input)
          st.text_area("Response:", value=result, height=100, disabled=False)
      
apis: llama_index.core.agent.ReActAgent.from_tools llama_index.core.query_engine.PandasQueryEngine llama_index.core.tools.ToolMetadata llama_index.llms.openai.OpenAI
extract_api: [((468, 481), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (479, 481), False, 'from dotenv import load_dotenv\n'), ((501, 539), 'os.path.join', 'os.path.join', (['"""data"""', '"""population.csv"""'], {}), "('data', 'population.csv')\n", (513, 539), False, 'import os\n'), ((556, 584), 'pandas.read_csv', 'pd.read_csv', (['population_path'], {}), '(population_path)\n', (567, 584), True, 'import pandas as pd\n'), ((612, 699), 'llama_index.core.query_engine.PandasQueryEngine', 'PandasQueryEngine', ([], {'df': 'population_df', 'verbose': '(True)', 'instruction_str': 'instruction_str'}), '(df=population_df, verbose=True, instruction_str=\n    instruction_str)\n', (629, 699), False, 'from llama_index.core.query_engine import PandasQueryEngine\n'), ((1517, 1551), 'llama_index.llms.openai.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo-0613"""'}), "(model='gpt-3.5-turbo-0613')\n", (1523, 1551), False, 'from llama_index.llms.openai import OpenAI\n'), ((1560, 1628), 'llama_index.core.agent.ReActAgent.from_tools', 'ReActAgent.from_tools', (['tools'], {'llm': 'llm', 'verbose': '(True)', 'context': 'context'}), '(tools, llm=llm, verbose=True, context=context)\n', (1581, 1628), False, 'from llama_index.core.agent import ReActAgent\n'), ((2824, 2849), 'streamlit.title', 'st.title', (['"""AgentAI - RAG"""'], {}), "('AgentAI - RAG')\n", (2832, 2849), True, 'import streamlit as st\n'), ((2864, 2896), 'streamlit.text_input', 'st.text_input', (['"""Enter a prompt:"""'], {}), "('Enter a prompt:')\n", (2877, 2896), True, 'import streamlit as st\n'), ((1821, 1849), 'streamlit.header', 'st.header', (['"""Upload PDF file"""'], {}), "('Upload PDF file')\n", (1830, 1849), True, 'import streamlit as st\n'), ((1861, 1895), 'streamlit.file_uploader', 'st.file_uploader', (['""""""'], {'type': "['pdf']"}), "('', type=['pdf'])\n", (1877, 1895), True, 'import streamlit as st\n'), ((2415, 2458), 'pdf.get_index', 'pdf_get_index', (['file_paths', '"""combined_index"""'], {}), "(file_paths, 'combined_index')\n", (2428, 2458), True, 'from pdf import get_index as pdf_get_index\n'), ((1930, 1961), 'os.path.join', 'os.path.join', (['"""data"""', 'file.name'], {}), "('data', file.name)\n", (1942, 1961), False, 'import os\n'), ((2138, 2192), 'streamlit.success', 'st.success', (['f"""File uploaded successfully: {file.name}"""'], {}), "(f'File uploaded successfully: {file.name}')\n", (2148, 2192), True, 'import streamlit as st\n'), ((2954, 2963), 'streamlit.stop', 'st.stop', ([], {}), '()\n', (2961, 2963), True, 'import streamlit as st\n'), ((3023, 3090), 'streamlit.text_area', 'st.text_area', (['"""Response:"""'], {'value': 'result', 'height': '(100)', 'disabled': '(False)'}), "('Response:', value=result, height=100, disabled=False)\n", (3035, 3090), True, 'import streamlit as st\n'), ((888, 1015), 'llama_index.core.tools.ToolMetadata', 'ToolMetadata', ([], {'name': '"""population_query_engine"""', 'description': '"""This gives information at the world population and demographic"""'}), "(name='population_query_engine', description=\n    'This gives information at the world population and demographic')\n", (900, 1015), False, 'from llama_index.core.tools import QueryEngineTool, ToolMetadata\n'), ((1371, 1468), 'llama_index.core.tools.ToolMetadata', 'ToolMetadata', ([], {'name': '"""combined_data"""', 'description': '"""This gives information from multiple files"""'}), "(name='combined_data', description=\n    'This gives information from multiple files')\n", (1383, 1468), False, 'from llama_index.core.tools import QueryEngineTool, ToolMetadata\n'), ((2665, 2762), 'llama_index.core.tools.ToolMetadata', 'ToolMetadata', ([], {'name': '"""combined_data"""', 'description': '"""This gives information from multiple files"""'}), "(name='combined_data', description=\n    'This gives information from multiple files')\n", (2677, 2762), False, 'from llama_index.core.tools import QueryEngineTool, ToolMetadata\n')]