Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -263,7 +263,7 @@ def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096,
|
|
263 |
print(" ")
|
264 |
print("------")
|
265 |
print(" ")
|
266 |
-
print(
|
267 |
print(" ")
|
268 |
print("------")
|
269 |
|
@@ -345,69 +345,6 @@ def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096,
|
|
345 |
# return PlainTextResponse(f"Error: {str(e)}")
|
346 |
|
347 |
|
348 |
-
|
349 |
-
# def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096, top_p: float = 1, top_k: int = 10, penalty: float = 1.0):
|
350 |
-
# try:
|
351 |
-
# model = AutoModelForCausalLM.from_pretrained(
|
352 |
-
# MODEL_ID,
|
353 |
-
# torch_dtype=torch.bfloat16,
|
354 |
-
# low_cpu_mem_usage=True,
|
355 |
-
# trust_remote_code=True
|
356 |
-
# )
|
357 |
-
|
358 |
-
# tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
359 |
-
|
360 |
-
# conversation = []
|
361 |
-
|
362 |
-
# # Acceder al contenido del archivo y al nombre del archivo
|
363 |
-
# if "file_content" in message and message["file_content"]:
|
364 |
-
# file_content = message["file_content"]
|
365 |
-
# file_name = message["file_name"]
|
366 |
-
|
367 |
-
# # Guardar el archivo en un archivo temporal
|
368 |
-
# with open(file_name, "wb") as f:
|
369 |
-
# f.write(file_content.read())
|
370 |
-
|
371 |
-
# # Llamar a `mode_load` con el nombre del archivo
|
372 |
-
# choice, contents = mode_load(file_name)
|
373 |
-
|
374 |
-
# if choice == "image":
|
375 |
-
# conversation.append({"role": "user", "image": contents, "content": message['text']})
|
376 |
-
# elif choice == "doc":
|
377 |
-
# format_msg = contents + "\n\n\n" + "{} files uploaded.\n".format(1) + message['text']
|
378 |
-
# conversation.append({"role": "user", "content": format_msg})
|
379 |
-
# else:
|
380 |
-
# # Manejar caso donde no se sube archivo
|
381 |
-
# conversation.append({"role": "user", "content": message['text']})
|
382 |
-
|
383 |
-
# print("--------------")
|
384 |
-
# print(" ")
|
385 |
-
# print(conversation)
|
386 |
-
# print(" ")
|
387 |
-
# print("--------------")
|
388 |
-
|
389 |
-
# input_ids = tokenizer.apply_chat_template(conversation, tokenize=True, add_generation_prompt=True, return_tensors="pt", return_dict=True).to(model.device)
|
390 |
-
|
391 |
-
# generate_kwargs = dict(
|
392 |
-
# max_length=max_length,
|
393 |
-
# do_sample=True,
|
394 |
-
# top_p=top_p,
|
395 |
-
# top_k=top_k,
|
396 |
-
# temperature=temperature,
|
397 |
-
# repetition_penalty=penalty,
|
398 |
-
# eos_token_id=[151329, 151336, 151338],
|
399 |
-
# )
|
400 |
-
|
401 |
-
# with torch.no_grad():
|
402 |
-
# generated_ids = model.generate(input_ids['input_ids'], **generate_kwargs)
|
403 |
-
# generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
404 |
-
|
405 |
-
|
406 |
-
# return PlainTextResponse(generated_text)
|
407 |
-
# except Exception as e:
|
408 |
-
# return PlainTextResponse(f"Error: {str(e)}")
|
409 |
-
|
410 |
-
|
411 |
|
412 |
@app.post("/chat/")
|
413 |
async def test_endpoint(
|
|
|
263 |
print(" ")
|
264 |
print("------")
|
265 |
print(" ")
|
266 |
+
print(generated_text)
|
267 |
print(" ")
|
268 |
print("------")
|
269 |
|
|
|
345 |
# return PlainTextResponse(f"Error: {str(e)}")
|
346 |
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
@app.post("/chat/")
|
350 |
async def test_endpoint(
|