Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -188,37 +188,13 @@ def get_llm(cfg):
|
|
188 |
|
189 |
|
190 |
def run(text, intensity):
|
191 |
-
# Configure logging
|
192 |
-
logging.basicConfig(level=logging.INFO,
|
193 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
194 |
-
logger = logging.getLogger(__name__)
|
195 |
-
sample_outputs = "start: "
|
196 |
-
|
197 |
-
try:
|
198 |
# Log the start of the process
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
# Load necessary components
|
205 |
-
prompt_template = get_prompt_template()
|
206 |
-
|
207 |
-
# Replace OpenAI embed model and llm with custom ones
|
208 |
-
reset_settings(config)
|
209 |
-
|
210 |
-
# Get retriever
|
211 |
-
retriever = get_retriever(config, prompt_template)
|
212 |
-
|
213 |
-
# Load tokenizer and language model
|
214 |
-
tokenizer = load_tokenizer(config)
|
215 |
-
language_model = get_llm(config)
|
216 |
-
prompt = retriever.query(text).response
|
217 |
-
prompt = tokenizer.bos_token + '[INST] ' + prompt + ' [/INST]'
|
218 |
-
streamer = TextStreamer(tokenizer, skip_prompt=True)
|
219 |
-
input_ids = tokenizer([prompt], return_tensors='pt').to(cfg.environment.device)
|
220 |
|
221 |
-
|
222 |
**input_ids,
|
223 |
streamer=streamer,
|
224 |
pad_token_id=tokenizer.pad_token_id,
|
@@ -227,27 +203,6 @@ def run(text, intensity):
|
|
227 |
temperature=cfg.generation.temperature
|
228 |
)
|
229 |
|
230 |
-
|
231 |
-
# Start the command line interface
|
232 |
-
# vistral_chat(config, retriever, tokenizer, language_model)
|
233 |
-
|
234 |
-
# Log successful completion
|
235 |
-
logger.info("Process completed successfully.")
|
236 |
-
|
237 |
-
except FileNotFoundError as e:
|
238 |
-
logger.error("Configuration file not found: %s", e)
|
239 |
-
|
240 |
-
except Exception as e:
|
241 |
-
logger.exception("An error occurred: %s", e)
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
# print(20*'---')
|
247 |
-
|
248 |
-
# res="Chatbot Data Mining 2024 \n \n \n"
|
249 |
-
# max_length=intensity
|
250 |
-
|
251 |
return sample_outputs
|
252 |
|
253 |
|
@@ -261,23 +216,6 @@ def vistral_chat():
|
|
261 |
|
262 |
|
263 |
|
264 |
-
# while True:
|
265 |
-
# user_query = input('👨🦰 ')
|
266 |
-
# prompt = retriever.query(user_query).response
|
267 |
-
# prompt = tokenizer.bos_token + '[INST] ' + prompt + ' [/INST]'
|
268 |
-
# streamer = TextStreamer(tokenizer, skip_prompt=True)
|
269 |
-
# input_ids = tokenizer([prompt], return_tensors='pt').to(cfg.environment.device)
|
270 |
-
|
271 |
-
# _ = language_model.generate(
|
272 |
-
# **input_ids,
|
273 |
-
# streamer=streamer,
|
274 |
-
# pad_token_id=tokenizer.pad_token_id,
|
275 |
-
# max_new_tokens=cfg.generation.max_new_tokens,
|
276 |
-
# do_sample=cfg.generation.do_sample,
|
277 |
-
# temperature=cfg.generation.temperature
|
278 |
-
# )
|
279 |
-
|
280 |
-
# print(20*'---')
|
281 |
|
282 |
|
283 |
def main1(config_path):
|
@@ -285,7 +223,10 @@ def main1(config_path):
|
|
285 |
logging.basicConfig(level=logging.INFO,
|
286 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
287 |
logger = logging.getLogger(__name__)
|
288 |
-
|
|
|
|
|
|
|
289 |
try:
|
290 |
# Log the start of the process
|
291 |
logger.info("Starting the process with config file: %s", config_path)
|
@@ -307,7 +248,7 @@ def main1(config_path):
|
|
307 |
language_model = get_llm(config)
|
308 |
|
309 |
# Start the command line interface
|
310 |
-
vistral_chat(
|
311 |
|
312 |
# Log successful completion
|
313 |
logger.info("Process completed successfully.")
|
|
|
188 |
|
189 |
|
190 |
def run(text, intensity):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
# Log the start of the process
|
192 |
+
prompt = retriever.query(text).response
|
193 |
+
prompt = tokenizer.bos_token + '[INST] ' + prompt + ' [/INST]'
|
194 |
+
streamer = TextStreamer(tokenizer, skip_prompt=True)
|
195 |
+
input_ids = tokenizer([prompt], return_tensors='pt').to(cfg.environment.device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
+
sample_outputs = language_model.generate(
|
198 |
**input_ids,
|
199 |
streamer=streamer,
|
200 |
pad_token_id=tokenizer.pad_token_id,
|
|
|
203 |
temperature=cfg.generation.temperature
|
204 |
)
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
return sample_outputs
|
207 |
|
208 |
|
|
|
216 |
|
217 |
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
|
221 |
def main1(config_path):
|
|
|
223 |
logging.basicConfig(level=logging.INFO,
|
224 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
225 |
logger = logging.getLogger(__name__)
|
226 |
+
global config = None
|
227 |
+
global retriever=None
|
228 |
+
global tokenizer=None
|
229 |
+
global language_model= None
|
230 |
try:
|
231 |
# Log the start of the process
|
232 |
logger.info("Starting the process with config file: %s", config_path)
|
|
|
248 |
language_model = get_llm(config)
|
249 |
|
250 |
# Start the command line interface
|
251 |
+
vistral_chat()
|
252 |
|
253 |
# Log successful completion
|
254 |
logger.info("Process completed successfully.")
|