code: from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage
  from langchain.chat_models import ChatOpenAI
  import gradio as gr
  
  
  class ChatbotIndex:
      def __init__(self, model_name, directory_path):
          self.llm_predictor = LLMPredictor(ChatOpenAI(model_name=model_name))
          self.service_context = ServiceContext.from_defaults(
              llm_predictor=self.llm_predictor)
          self.docs = SimpleDirectoryReader(directory_path).load_data()
  
      def construct_index(self):
          self.index = GPTVectorStoreIndex.from_documents(
              self.docs, service_context=self.service_context)
          self.index.storage_context.persist(persist_dir='index')
          return self.index
  
      def load_index(self):
          storage_context = StorageContext.from_defaults(persist_dir="index")
          self.index = load_index_from_storage(storage_context)
  
      def query_response(self, input_text):
          query_engine = self.index.as_query_engine()
          response = query_engine.query(input_text)
          print(response)
          return response.response
  
  
  def launch_chatbot_interface():
      chatbot = ChatbotIndex(model_name='gpt-3.5-turbo', directory_path="data")
      chatbot.construct_index()
  
      iface = gr.Interface(fn=chatbot.query_response, inputs="text",
                           outputs="text", title="LocalGPT Chatbot")
      iface.launch(share=True)
  
  
  if __name__ == "__main__":
      launch_chatbot_interface()
  
apis: llama_index.GPTVectorStoreIndex.from_documents llama_index.ServiceContext.from_defaults llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.load_index_from_storage
extract_api: [((1293, 1393), 'gradio.Interface', 'gr.Interface', ([], {'fn': 'chatbot.query_response', 'inputs': '"""text"""', 'outputs': '"""text"""', 'title': '"""LocalGPT Chatbot"""'}), "(fn=chatbot.query_response, inputs='text', outputs='text',\n    title='LocalGPT Chatbot')\n", (1305, 1393), True, 'import gradio as gr\n'), ((385, 447), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'self.llm_predictor'}), '(llm_predictor=self.llm_predictor)\n', (413, 447), False, 'from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage\n'), ((584, 672), 'llama_index.GPTVectorStoreIndex.from_documents', 'GPTVectorStoreIndex.from_documents', (['self.docs'], {'service_context': 'self.service_context'}), '(self.docs, service_context=self.\n    service_context)\n', (618, 672), False, 'from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage\n'), ((824, 873), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': '"""index"""'}), "(persist_dir='index')\n", (852, 873), False, 'from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage\n'), ((895, 935), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (918, 935), False, 'from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage\n'), ((319, 352), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'model_name': 'model_name'}), '(model_name=model_name)\n', (329, 352), False, 'from langchain.chat_models import ChatOpenAI\n'), ((481, 518), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['directory_path'], {}), '(directory_path)\n', (502, 518), False, 'from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, ServiceContext, StorageContext, load_index_from_storage\n')]