RufiDev commited on
Commit
bf236aa
·
verified ·
1 Parent(s): b68e86b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -8,6 +8,7 @@ from llama_index.llms.openai import OpenAI
8
  # Configuração inicial
9
  GIT_REPO = "https://github.com/luiz-ouroboros/payment_api.git"
10
  PROJECT_DIR = "payment_api"
 
11
 
12
  # Baixar o repositório do GitHub (se não existir)
13
  if not os.path.exists(PROJECT_DIR):
@@ -25,9 +26,17 @@ Settings.embed_model = OpenAIEmbedding()
25
  # Lendo os arquivos do projeto
26
  documents = SimpleDirectoryReader(PROJECT_DIR).load_data()
27
 
28
- # Criando um índice vetorial para buscas
29
- storage_context = StorageContext.from_defaults(persist_dir="storage")
30
- index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
 
 
 
 
 
 
 
 
31
 
32
  # Função para responder perguntas sobre o projeto
33
  def respond(message, history):
@@ -39,4 +48,4 @@ def respond(message, history):
39
  demo = gr.ChatInterface(respond, title="IA Especializada no Meu Projeto")
40
 
41
  if __name__ == "__main__":
42
- demo.launch()
 
8
  # Configuração inicial
9
  GIT_REPO = "https://github.com/luiz-ouroboros/payment_api.git"
10
  PROJECT_DIR = "payment_api"
11
+ STORAGE_DIR = "storage"
12
 
13
  # Baixar o repositório do GitHub (se não existir)
14
  if not os.path.exists(PROJECT_DIR):
 
26
  # Lendo os arquivos do projeto
27
  documents = SimpleDirectoryReader(PROJECT_DIR).load_data()
28
 
29
+ # Verificar se o diretório de persistência existe
30
+ if not os.path.exists(STORAGE_DIR):
31
+ # Criar o índice e persistir os dados
32
+ print("Criando índice e persistindo dados...")
33
+ index = VectorStoreIndex.from_documents(documents)
34
+ index.storage_context.persist(persist_dir=STORAGE_DIR)
35
+ else:
36
+ # Carregar o índice existente
37
+ print("Carregando índice existente...")
38
+ storage_context = StorageContext.from_defaults(persist_dir=STORAGE_DIR)
39
+ index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
40
 
41
  # Função para responder perguntas sobre o projeto
42
  def respond(message, history):
 
48
  demo = gr.ChatInterface(respond, title="IA Especializada no Meu Projeto")
49
 
50
  if __name__ == "__main__":
51
+ demo.launch()