aldohenrique commited on
Commit
2253ce8
·
verified ·
1 Parent(s): b638ed1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -11
app.py CHANGED
@@ -5,29 +5,90 @@ Arquivo principal que inicializa o sistema
5
  """
6
 
7
  import os
8
- from ai_logic import load_vector_store, HF_TOKEN
 
9
  from interface import configurar_interface
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def main():
12
  """Função principal que inicializa o sistema"""
13
  print("🚀 Iniciando Dr. Aldo Henrique com RAG...")
14
-
15
  # Verificar se o token HF está configurado
16
  if not HF_TOKEN:
17
  print("❌ Erro: Token HF_TOKEN não encontrado nas variáveis de ambiente")
18
  return
19
-
20
  print(f"🔑 Token HF encontrado: {HF_TOKEN[:8]}...")
21
-
22
- # Carrega ou constrói o vector store na inicialização
 
 
 
23
  load_vector_store()
24
-
25
- # Configurar a interface
26
  interface = configurar_interface()
27
-
28
  print("🌐 Interface pronta!")
29
-
30
- # Lançar a aplicação
31
  interface.launch(
32
  server_name="0.0.0.0",
33
  server_port=7860,
@@ -36,5 +97,6 @@ def main():
36
  show_error=True
37
  )
38
 
 
39
  if __name__ == "__main__":
40
- main()
 
5
  """
6
 
7
  import os
8
+ from huggingface_hub import hf_hub_download
9
+ from ai_logic import load_vector_store
10
  from interface import configurar_interface
11
 
12
+
13
+ # 🔑 Token do Hugging Face vindo das variáveis de ambiente
14
+ HF_TOKEN = os.getenv("HF_TOKEN")
15
+
16
+ # Lista de modelos para testar acesso
17
+ MODELS = [
18
+ {"name": "Mistral-7B-Instruct-v0.3", "repo_id": "mistralai/Mistral-7B-Instruct-v0.3"},
19
+ {"name": "Mistral-7B-v0.1", "repo_id": "mistralai/Mistral-7B-v0.1"},
20
+ {"name": "Mixtral-8x7B-Instruct-v0.1", "repo_id": "mistralai/Mixtral-8x7B-Instruct-v0.1"},
21
+ {"name": "Phi-3-mini-4k-instruct", "repo_id": "microsoft/Phi-3-mini-4k-instruct"},
22
+ {"name": "Phi-3-small-8k-instruct", "repo_id": "microsoft/Phi-3-small-8k-instruct"},
23
+ {"name": "DeepSeek-R1-Distill-Qwen-7B", "repo_id": "unsloth/DeepSeek-R1-Distill-Qwen-7B"},
24
+ {"name": "DeepSeek-Coder-V2-Lite", "repo_id": "DeepSeek/DeepSeek-Coder-V2-Lite"},
25
+ {"name": "Gemma-2-9B", "repo_id": "google/gemma-2-9b"},
26
+ {"name": "Gemma-3-4B", "repo_id": "google/gemma-3-4b"},
27
+ {"name": "LLaMA-3.1-8B-Instruct", "repo_id": "meta-llama/Llama-3.1-8B-Instruct"},
28
+ {"name": "Qwen2-7B-Instruct", "repo_id": "Qwen/Qwen2-7B-Instruct"},
29
+ {"name": "Qwen2.5-7B-Instruct", "repo_id": "Qwen/Qwen2.5-7B-Instruct"},
30
+ {"name": "Zephyr-7B-Beta", "repo_id": "HuggingFaceH4/zephyr-7b-beta"},
31
+ {"name": "OpenHermes-2.5-Mistral-7B", "repo_id": "teknium/OpenHermes-2.5-Mistral-7B"},
32
+ {"name": "Falcon-7B-Instruct", "repo_id": "tiiuae/falcon-7b-instruct"},
33
+ {"name": "Yi-6B", "repo_id": "01-ai/Yi-6B"},
34
+ {"name": "XGen-7B-Instruct", "repo_id": "Salesforce/xgen-7b-8k-instruct"},
35
+ {"name": "StableLM-3B-4e1t", "repo_id": "stabilityai/stablelm-3b-4e1t"},
36
+ {"name": "Mistral-NeMo", "repo_id": "mistralai/Mixtral-NeMo"},
37
+ {"name": "Mathstral-7B", "repo_id": "mistralai/Mathstral-7B"}
38
+ ]
39
+
40
+
41
+ def testar_acesso_modelos():
42
+ """Testa o acesso a cada modelo da lista."""
43
+ if not HF_TOKEN:
44
+ print("⚠️ Token Hugging Face não encontrado. Pulando teste de acesso aos modelos.\n")
45
+ return
46
+
47
+ print("\n🔍 Testando acesso aos modelos Hugging Face...\n")
48
+ resultados = []
49
+ for modelo in MODELS:
50
+ nome = modelo["name"]
51
+ repo_id = modelo["repo_id"]
52
+ try:
53
+ hf_hub_download(
54
+ repo_id=repo_id,
55
+ filename="config.json",
56
+ token=HF_TOKEN
57
+ )
58
+ resultados.append(f"✅ {nome}: Acesso OK")
59
+ except Exception as e:
60
+ resultados.append(f"❌ {nome}: Sem acesso ({str(e)})")
61
+
62
+ print("🗒️ Resultado dos testes de acesso:")
63
+ print("------------------------------------------------")
64
+ for r in resultados:
65
+ print(r)
66
+ print("------------------------------------------------\n")
67
+
68
+
69
  def main():
70
  """Função principal que inicializa o sistema"""
71
  print("🚀 Iniciando Dr. Aldo Henrique com RAG...")
72
+
73
  # Verificar se o token HF está configurado
74
  if not HF_TOKEN:
75
  print("❌ Erro: Token HF_TOKEN não encontrado nas variáveis de ambiente")
76
  return
77
+
78
  print(f"🔑 Token HF encontrado: {HF_TOKEN[:8]}...")
79
+
80
+ # 🔍 Testar acesso aos modelos (opcional, apenas informativo)
81
+ testar_acesso_modelos()
82
+
83
+ # ⚙️ Carrega ou constrói o vector store
84
  load_vector_store()
85
+
86
+ # 🌐 Configura a interface
87
  interface = configurar_interface()
88
+
89
  print("🌐 Interface pronta!")
90
+
91
+ # 🚀 Lançar a aplicação
92
  interface.launch(
93
  server_name="0.0.0.0",
94
  server_port=7860,
 
97
  show_error=True
98
  )
99
 
100
+
101
  if __name__ == "__main__":
102
+ main()