leandroaraujodev commited on
Commit
a168116
1 Parent(s): 089cea4

update model

Browse files
app.py CHANGED
@@ -30,6 +30,12 @@ import huggingface_hub
30
  import logging
31
  import sys
32
  from PIL import Image
 
 
 
 
 
 
33
 
34
  #Token do huggingface
35
  HF_TOKEN: Optional[str] = os.getenv("HF_TOKEN")
@@ -54,7 +60,7 @@ for pasta in pastas:
54
 
55
  # Configuração do Streamlit
56
  st.sidebar.title("Configuração de LLM")
57
- sidebar_option = st.sidebar.radio("Selecione o LLM", ["Ollama", "OpenAI", "HF Local"])
58
  # logo_url = 'app\logos\logo-sicoob.jpg'
59
  # st.sidebar.image(logo_url)
60
  import base64
@@ -73,12 +79,13 @@ with open("sicoob-logo.png", "rb") as f:
73
  )
74
 
75
 
76
- if sidebar_option == "Ollama":
77
- Settings.llm = Ollama(model="llama3.2:latest", request_timeout=500.0, num_gpu=1)
78
- Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text:latest")
79
- elif sidebar_option == "OpenAI":
80
  from llama_index.llms.openai import OpenAI
81
  from llama_index.embeddings.openai import OpenAIEmbedding
 
82
  Settings.llm = OpenAI(model="gpt-3.5-turbo")
83
  Settings.embed_model = OpenAIEmbedding(model_name="text-embedding-ada-002")
84
  elif sidebar_option == 'HF Local':
@@ -86,41 +93,53 @@ elif sidebar_option == 'HF Local':
86
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
87
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
88
 
89
- query_wrapper_prompt = PromptTemplate(
90
- "Você é um assistente virtual capaz de interagir normalmente, além de"
91
- " fornecer informações sobre organogramas e listar funcionários."
92
- " Aqui estão os documentos relevantes para o contexto:\n"
93
- "{context_str}"
94
- "\nInstrução: Use o histórico da conversa anterior, ou o contexto acima, para responder."
95
- )
96
  #Embedding do huggingface
97
  Settings.embed_model = HuggingFaceEmbedding(
98
  model_name="BAAI/bge-small-en-v1.5"
99
  )
100
-
101
  #Carregamento do modelo local, descomentar o modelo desejado
 
102
  llm = HuggingFaceLLM(
103
- # context_window=2048,
104
- # max_new_tokens=256,
105
- # generate_kwargs={"do_sample": False},
106
- # query_wrapper_prompt=query_wrapper_prompt,
107
  #model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
108
  #model_name="Qwen/Qwen2.5-14B-Instruct",
109
  # model_name="meta-llama/Llama-3.2-3B",
110
  #model_name="HuggingFaceH4/zephyr-7b-beta",
111
  # model_name="meta-llama/Meta-Llama-3-8B",
112
- #model_name="numind/NuExtract-1.5",
113
- model_name="meta-llama/Llama-3.2-3B",
114
 
115
- tokenizer_name="meta-llama/Llama-3.2-3B",
116
  device_map="auto",
117
- # tokenizer_kwargs={"max_length": 2048},
118
  # uncomment this if using CUDA to reduce memory usage
119
- model_kwargs={"torch_dtype": torch.float16},
120
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
 
122
 
123
- # Settings.chunk_size = 512
124
  Settings.llm = llm
125
 
126
  else:
 
30
  import logging
31
  import sys
32
  from PIL import Image
33
+ import gc
34
+
35
+ def flush():
36
+ gc.collect()
37
+ torch.cuda.empty_cache()
38
+ torch.cuda.reset_peak_memory_stats()
39
 
40
  #Token do huggingface
41
  HF_TOKEN: Optional[str] = os.getenv("HF_TOKEN")
 
60
 
61
  # Configuração do Streamlit
62
  st.sidebar.title("Configuração de LLM")
63
+ sidebar_option = st.sidebar.radio("Selecione o LLM", ["OpenAI", "HF Local"])
64
  # logo_url = 'app\logos\logo-sicoob.jpg'
65
  # st.sidebar.image(logo_url)
66
  import base64
 
79
  )
80
 
81
 
82
+ #if sidebar_option == "Ollama":
83
+ # Settings.llm = Ollama(model="llama3.2:latest", request_timeout=500.0, num_gpu=1)
84
+ # Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text:latest")
85
+ if sidebar_option == "gpt-3.5":
86
  from llama_index.llms.openai import OpenAI
87
  from llama_index.embeddings.openai import OpenAIEmbedding
88
+ os.environ["OPENAI_API_KEY"] = "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"
89
  Settings.llm = OpenAI(model="gpt-3.5-turbo")
90
  Settings.embed_model = OpenAIEmbedding(model_name="text-embedding-ada-002")
91
  elif sidebar_option == 'HF Local':
 
93
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
94
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
95
 
96
+ #query_wrapper_prompt = PromptTemplate(
97
+ #"Below are several documents about a company "
98
+ #"Write a response that appropriately completes the request.\n\n"
99
+ #"### Instruction:\n{query_str}\n\n### Response:"
100
+ #)
 
 
101
  #Embedding do huggingface
102
  Settings.embed_model = HuggingFaceEmbedding(
103
  model_name="BAAI/bge-small-en-v1.5"
104
  )
 
105
  #Carregamento do modelo local, descomentar o modelo desejado
106
+
107
  llm = HuggingFaceLLM(
108
+ context_window=2048,
109
+ max_new_tokens=256,
110
+ generate_kwargs={"do_sample": False},
111
+ #query_wrapper_prompt=query_wrapper_prompt,
112
  #model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
113
  #model_name="Qwen/Qwen2.5-14B-Instruct",
114
  # model_name="meta-llama/Llama-3.2-3B",
115
  #model_name="HuggingFaceH4/zephyr-7b-beta",
116
  # model_name="meta-llama/Meta-Llama-3-8B",
117
+ model_name="numind/NuExtract-1.5",
118
+ #model_name="meta-llama/Llama-3.2-3B",
119
 
120
+ tokenizer_name="numind/NuExtract-1.5",
121
  device_map="auto",
122
+ tokenizer_kwargs={"max_length": 2048},
123
  # uncomment this if using CUDA to reduce memory usage
124
+ model_kwargs={"torch_dtype": torch.bfloat16},
125
  )
126
+ chat = [
127
+
128
+ {"role": "user", "content": "Hello, how are you?"},
129
+
130
+ {"role": "assistant", "content": "I'm doing great. How can I help you today?"},
131
+
132
+ {"role": "user", "content": "I'd like to show off how chat templating works!"},
133
+
134
+ ]
135
+
136
+ from transformers import AutoTokenizer
137
+
138
+ tokenizer = AutoTokenizer.from_pretrained("numind/NuExtract-1.5")
139
 
140
+ tokenizer.apply_chat_template(chat, tokenize=False)
141
 
142
+ Settings.chunk_size = 512
143
  Settings.llm = llm
144
 
145
  else:
documentos/empresa.pdf ADDED
Binary file (58.8 kB). View file
 
documentos/lista_funcionarios.pdf ADDED
Binary file (38.6 kB). View file