Spaces:
Running
on
Zero
Running
on
Zero
Update config.py
Browse files
config.py
CHANGED
@@ -1,36 +1,28 @@
|
|
1 |
-
#
|
2 |
-
|
3 |
-
import
|
4 |
-
from
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# Prompt del sistema para Yi-Coder
|
30 |
-
SYSTEM_PROMPT = """
|
31 |
-
Eres un asistente en salud neonatal en Perú, responde y saluda de forma adecuada,
|
32 |
-
solo responde en forma de texto de usuario no del chat completo.
|
33 |
-
"""
|
34 |
-
|
35 |
-
# Longitud máxima por defecto para las respuestas generadas
|
36 |
-
MAX_LENGTH_DEFAULT = 100
|
|
|
1 |
+
# models.py
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
+
from sentence_transformers import SentenceTransformer
|
6 |
+
from config import EMBEDDING_MODEL_NAME
|
7 |
+
from pydantic import BaseModel
|
8 |
+
|
9 |
+
# Clase para los modelos (opcional, si deseas utilizar pydantic)
|
10 |
+
class Models(BaseModel):
|
11 |
+
embedding_model: SentenceTransformer
|
12 |
+
tokenizer: AutoTokenizer
|
13 |
+
yi_coder_model: AutoModelForCausalLM
|
14 |
+
device: torch.device
|
15 |
+
|
16 |
+
# Cargar el modelo de embeddings
|
17 |
+
def load_embedding_model():
|
18 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
19 |
+
embedding_model = SentenceTransformer(EMBEDDING_MODEL_NAME, device=device)
|
20 |
+
return embedding_model
|
21 |
+
|
22 |
+
# Cargar el modelo Yi-Coder
|
23 |
+
def load_yi_coder_model():
|
24 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
25 |
+
model_path = "01-ai/Yi-Coder-9B-Chat" # Asegúrate de que esta ruta sea correcta
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
27 |
+
yi_coder_model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16).to(device).eval()
|
28 |
+
return tokenizer, yi_coder_model, device
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|