Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,24 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
|
| 4 |
-
# Cargar el
|
| 5 |
-
|
| 6 |
-
"JuanCabs/lapepav0",
|
| 7 |
-
device_map="auto" # Asigna autom谩ticamente el dispositivo CPU/GPU disponible
|
| 8 |
-
)
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained("JuanCabs/lapepav0")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
outputs = model.generate(**inputs, max_length=100)
|
| 15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
outputs="text", # Salida de texto
|
| 22 |
-
title="Text Generation with Model", # T铆tulo del Space
|
| 23 |
-
description="Introduce un prompt para generar texto usando el modelo" # Descripci贸n
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# Lanzar la aplicaci贸n
|
| 27 |
-
interface.launch()
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import torch
|
| 3 |
|
| 4 |
+
# Cargar el tokenizer del modelo base
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("unsloth/meta-llama-3.1-8b-bnb-4bit")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Cargar el modelo base
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained("unsloth/meta-llama-3.1-8b-bnb-4bit",
|
| 9 |
+
load_in_4bit=True,
|
| 10 |
+
device_map="auto")
|
| 11 |
+
|
| 12 |
+
# Cargar el adaptador LoRA
|
| 13 |
+
model.load_adapter("JuanCabs/lapepav1", source="hf")
|
| 14 |
+
|
| 15 |
+
# Prueba de generaci贸n de texto
|
| 16 |
+
def generar_respuesta(prompt):
|
| 17 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 18 |
outputs = model.generate(**inputs, max_length=100)
|
| 19 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 20 |
|
| 21 |
+
# Ejemplo de uso
|
| 22 |
+
prompt = "驴C贸mo ser谩 el futuro de la inteligencia artificial?"
|
| 23 |
+
respuesta = generar_respuesta(prompt)
|
| 24 |
+
print(respuesta)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|