Jeice commited on
Commit
c393df3
·
verified ·
1 Parent(s): 0115514

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -4,45 +4,47 @@ from huggingface_hub import snapshot_download
4
  import gradio as gr
5
  import os
6
 
7
- #Configure sua API da OpenAI (ou pode trocar por HuggingFace LLM depois)
8
- os.environ["OPENAI_API_KEY"] = "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" # Coloque sua chave da OpenAI aqui
9
 
10
- #Baixar os arquivos do dataset no Hugging Face
11
- print("📥 Baixando documentação...")
12
- docs_dir = snapshot_download(repo_id="Jeice/n8n-docs-v2")
 
 
13
 
14
- #Carregar os documentos
15
  documents = SimpleDirectoryReader(docs_dir).load_data()
16
 
17
- #Criar o índice vetorial
18
  service_context = ServiceContext.from_defaults(
19
  llm=OpenAI(model="gpt-3.5-turbo")
20
  )
21
  index = VectorStoreIndex.from_documents(documents, service_context=service_context)
22
 
23
- #Criar engine de consulta
24
  query_engine = index.as_query_engine()
25
 
26
- #Função do chatbot
27
  def chatbot(input_text):
28
  response = query_engine.query(input_text)
29
  return str(response)
30
 
31
- #Interface Gradio — bonita, limpa e simples
32
  interface = gr.Interface(
33
  fn=chatbot,
34
  inputs=gr.Textbox(lines=2, placeholder="Digite sua pergunta sobre o n8n..."),
35
  outputs="text",
36
  title="🤖 Bot de Dúvidas sobre o n8n",
37
- description="Este agente responde dúvidas sobre o n8n, baseado na documentação que você subiu para o Hugging Face.",
38
- theme="default",
39
  examples=[
40
  ["Como criar um workflow no n8n?"],
41
  ["Para que serve o node HTTP Request?"],
42
  ["Quais são os nodes para integração com Google Sheets?"],
43
  ],
 
44
  allow_flagging="never"
45
  )
46
 
47
- #Rodar o app
48
  interface.launch()
 
4
  import gradio as gr
5
  import os
6
 
7
+ # 🔑 Configure sua API da OpenAI (adicione no Hugging Face em Settings > Secrets)
8
+ os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
9
 
10
+ # 📥 Baixar a documentação do Hugging Face Dataset
11
+ docs_dir = snapshot_download(
12
+ repo_id="Jeice/n8n-docs-v2",
13
+ repo_type="dataset"
14
+ )
15
 
16
+ # 📚 Carregar os documentos
17
  documents = SimpleDirectoryReader(docs_dir).load_data()
18
 
19
+ # 🔎 Criar o índice vetorial
20
  service_context = ServiceContext.from_defaults(
21
  llm=OpenAI(model="gpt-3.5-turbo")
22
  )
23
  index = VectorStoreIndex.from_documents(documents, service_context=service_context)
24
 
25
+ # 🚀 Criar engine de consulta
26
  query_engine = index.as_query_engine()
27
 
28
+ # 💬 Função do chatbot
29
  def chatbot(input_text):
30
  response = query_engine.query(input_text)
31
  return str(response)
32
 
33
+ # 🎨 Interface Gradio — Bonita e Funcional
34
  interface = gr.Interface(
35
  fn=chatbot,
36
  inputs=gr.Textbox(lines=2, placeholder="Digite sua pergunta sobre o n8n..."),
37
  outputs="text",
38
  title="🤖 Bot de Dúvidas sobre o n8n",
39
+ description="Este agente responde dúvidas sobre o n8n, baseado na documentação oficial.",
 
40
  examples=[
41
  ["Como criar um workflow no n8n?"],
42
  ["Para que serve o node HTTP Request?"],
43
  ["Quais são os nodes para integração com Google Sheets?"],
44
  ],
45
+ theme="default",
46
  allow_flagging="never"
47
  )
48
 
49
+ # 🚀 Executar
50
  interface.launch()