code: from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage
  from langchain.chat_models import ChatOpenAI
  import gradio as gr
  import sys
  import os
  import openai
  
  openai.api_base = "https://api.app4gpt.com/v1"
  os.environ["OPENAI_API_KEY"] = 'you-API-KEY'
  
  def create_service_context():
  
      #constraint parameters
      max_input_size = 4096
      num_outputs = 3072
      max_chunk_overlap = 20
      chunk_size_limit = 600
  
      #allows the user to explicitly set certain constraint parameters
      prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
  
      #LLMPredictor is a wrapper class around LangChain's LLMChain that allows easy integration into LlamaIndex
      llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
  
      #constructs service_context
      service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
      return service_context
  
  
  def data_ingestion_indexing(directory_path):
  
      #loads data from the specified directory path
      documents = SimpleDirectoryReader(directory_path).load_data()
      
      #when first building the index
      index = GPTVectorStoreIndex.from_documents(
          documents, service_context=create_service_context()
      )
  
      #persist index to disk, default "storage" folder
      index.storage_context.persist()
  
      return index
  
  def data_querying(input_text):
  
      #rebuild storage context
      storage_context = StorageContext.from_defaults(persist_dir="./storage")
  
      #loads index from storage
      index = load_index_from_storage(storage_context, service_context=create_service_context())
      
      #queries the index with the input text
      response = index.as_query_engine().query(input_text)
      
      return response.response
  
  iface = gr.Interface(fn=data_querying,
                       inputs=gr.components.Textbox(lines=7, label="Enter your question"),
                       outputs="text",
                       title="Custom-Pdf Demo by Gpt4")
  
  #passes in data directory
  index = data_ingestion_indexing("data")
  iface.launch(share=False)
  
apis: llama_index.PromptHelper llama_index.ServiceContext.from_defaults llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader
extract_api: [((597, 696), 'llama_index.PromptHelper', 'PromptHelper', (['max_input_size', 'num_outputs', 'max_chunk_overlap'], {'chunk_size_limit': 'chunk_size_limit'}), '(max_input_size, num_outputs, max_chunk_overlap,\n    chunk_size_limit=chunk_size_limit)\n', (609, 696), False, 'from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage\n'), ((977, 1068), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'llm_predictor', 'prompt_helper': 'prompt_helper'}), '(llm_predictor=llm_predictor, prompt_helper=\n    prompt_helper)\n', (1005, 1068), False, 'from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage\n'), ((1601, 1654), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': '"""./storage"""'}), "(persist_dir='./storage')\n", (1629, 1654), False, 'from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage\n'), ((1988, 2047), 'gradio.components.Textbox', 'gr.components.Textbox', ([], {'lines': '(7)', 'label': '"""Enter your question"""'}), "(lines=7, label='Enter your question')\n", (2009, 2047), True, 'import gradio as gr\n'), ((841, 920), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0.5)', 'model_name': '"""gpt-3.5-turbo"""', 'max_tokens': 'num_outputs'}), "(temperature=0.5, model_name='gpt-3.5-turbo', max_tokens=num_outputs)\n", (851, 920), False, 'from langchain.chat_models import ChatOpenAI\n'), ((1205, 1242), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['directory_path'], {}), '(directory_path)\n', (1226, 1242), False, 'from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage\n')]