Jeice commited on
Commit
56f49e5
·
verified ·
1 Parent(s): 7e7ccfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -7,11 +7,11 @@ import yaml
7
  import json
8
 
9
 
10
- # 🔑 Configure sua API da OpenAI (adicione no Hugging Face em Settings > Secrets)
11
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
12
 
13
 
14
- # 🔥 Função para extrair conteúdo de YAML, JSON, TXT e MD
15
  def extrair_conteudo_dos_arquivos(pasta):
16
  texto_final = ""
17
 
@@ -46,7 +46,7 @@ def extrair_conteudo_dos_arquivos(pasta):
46
  return texto_final
47
 
48
 
49
- # 🔧 Função para gerar o arquivo documentacao.txt
50
  def gerar_arquivo_documentacao(pasta_origem, arquivo_destino="documentacao.txt"):
51
  texto = extrair_conteudo_dos_arquivos(pasta_origem)
52
 
@@ -58,39 +58,39 @@ def gerar_arquivo_documentacao(pasta_origem, arquivo_destino="documentacao.txt")
58
  print(f"✅ Arquivo {arquivo_destino} gerado com sucesso.")
59
 
60
 
61
- # 📥 Baixar a documentação do Hugging Face Dataset
62
  docs_dir = snapshot_download(
63
  repo_id="Jeice/n8n-docs-v2",
64
  repo_type="dataset"
65
  )
66
 
67
 
68
- # 🔨 Gerar o arquivo de documentação consolidado
69
  gerar_arquivo_documentacao(docs_dir)
70
 
71
 
72
- # 📚 Carregar o documento gerado
73
  documents = SimpleDirectoryReader(input_files=["documentacao.txt"]).load_data()
74
 
75
 
76
- # 🧠 ✅ Definir o LLM (agora com Settings no lugar de ServiceContext)
77
  Settings.llm = OpenAI(model="gpt-3.5-turbo")
78
 
79
- # 🔎 Criar o índice vetorial
80
  index = VectorStoreIndex.from_documents(documents)
81
 
82
 
83
- # 🚀 Criar engine de consulta
84
  query_engine = index.as_query_engine()
85
 
86
 
87
- # 💬 Função do chatbot
88
  def chatbot(input_text):
89
  response = query_engine.query(input_text)
90
  return str(response)
91
 
92
 
93
- # 🎨 Interface Gradio — Bonita e Funcional
94
  interface = gr.Interface(
95
  fn=chatbot,
96
  inputs=gr.Textbox(lines=2, placeholder="Digite sua pergunta sobre o n8n..."),
@@ -107,5 +107,5 @@ interface = gr.Interface(
107
  )
108
 
109
 
110
- # 🚀 Executar
111
  interface.launch()
 
7
  import json
8
 
9
 
10
+ #Configure sua API da OpenAI (adicione no Hugging Face em Settings > Secrets)
11
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
12
 
13
 
14
+ #Função para extrair conteúdo de YAML, JSON, TXT e MD
15
  def extrair_conteudo_dos_arquivos(pasta):
16
  texto_final = ""
17
 
 
46
  return texto_final
47
 
48
 
49
+ #Função para gerar o arquivo documentacao.txt
50
  def gerar_arquivo_documentacao(pasta_origem, arquivo_destino="documentacao.txt"):
51
  texto = extrair_conteudo_dos_arquivos(pasta_origem)
52
 
 
58
  print(f"✅ Arquivo {arquivo_destino} gerado com sucesso.")
59
 
60
 
61
+ #Baixar a documentação do Hugging Face Dataset
62
  docs_dir = snapshot_download(
63
  repo_id="Jeice/n8n-docs-v2",
64
  repo_type="dataset"
65
  )
66
 
67
 
68
+ #Gerar o arquivo de documentação consolidado
69
  gerar_arquivo_documentacao(docs_dir)
70
 
71
 
72
+ #Carregar o documento gerado
73
  documents = SimpleDirectoryReader(input_files=["documentacao.txt"]).load_data()
74
 
75
 
76
+ #Definir o LLM (agora com Settings no lugar de ServiceContext)
77
  Settings.llm = OpenAI(model="gpt-3.5-turbo")
78
 
79
+ #Criar o índice vetorial
80
  index = VectorStoreIndex.from_documents(documents)
81
 
82
 
83
+ #Criar engine de consulta
84
  query_engine = index.as_query_engine()
85
 
86
 
87
+ #Função do chatbot
88
  def chatbot(input_text):
89
  response = query_engine.query(input_text)
90
  return str(response)
91
 
92
 
93
+ #Interface Gradio — Bonita e Funcional
94
  interface = gr.Interface(
95
  fn=chatbot,
96
  inputs=gr.Textbox(lines=2, placeholder="Digite sua pergunta sobre o n8n..."),
 
107
  )
108
 
109
 
110
+ #Executar
111
  interface.launch()