AxoneSystem commited on
Commit
a268a35
·
verified ·
1 Parent(s): 4630fd5

Upload 3 files

Browse files
Files changed (2) hide show
  1. README.md +14 -6
  2. app.py +16 -4
README.md CHANGED
@@ -1,11 +1,19 @@
1
  ---
2
  title: Minerva Chat
3
- emoji: 📊
4
- colorFrom: pink
5
- colorTo: pink
6
- sdk: static
 
 
 
7
  pinned: false
8
- license: cc-by-nd-4.0
 
 
 
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
  title: Minerva Chat
3
+ emoji: 🦉
4
+ colorFrom: purple
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 6.28.0
8
+ python_version: "3.12"
9
+ app_file: app.py
10
  pinned: false
11
+ license: cc-by-nc-4.0
12
+ short_description: Chatea con Minerva v0.1, un modelo diminuto en español
13
+ models:
14
+ - AxoneSystem/Minerva-v0.1
15
  ---
16
 
17
+ Chat con [Minerva v0.1](https://huggingface.co/AxoneSystem/Minerva-v0.1), un modelo de lenguaje en español
18
+ de 30 millones de parámetros entrenado desde cero en un portátil. Es un modelo de juguete: habla bien,
19
+ pero se inventa casi todo.
app.py CHANGED
@@ -10,15 +10,27 @@ CONTEXTO = 512 # tokens que Minerva puede ver a la vez
10
  MAX_RESPUESTA = 200
11
 
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  def a_mensajes(historial):
14
  """Acepta el historial de Gradio en formato de mensajes o de pares (según la versión)."""
15
  mensajes = []
16
  for item in historial or []:
17
  if isinstance(item, dict):
18
- if item.get("role") in ("user", "assistant") and isinstance(item.get("content"), str):
19
- mensajes.append({"role": item["role"], "content": item["content"]})
 
20
  else:
21
- usuario, asistente = item[0], item[1]
22
  if usuario:
23
  mensajes.append({"role": "user", "content": usuario})
24
  if asistente:
@@ -27,7 +39,7 @@ def a_mensajes(historial):
27
 
28
 
29
  def responder(mensaje, historial, temperatura):
30
- mensajes = a_mensajes(historial) + [{"role": "user", "content": mensaje}]
31
  entrada = tok.apply_chat_template(mensajes, add_generation_prompt=True, return_tensors="pt", return_dict=True)
32
  ids = entrada["input_ids"][:, -(CONTEXTO - MAX_RESPUESTA):] # solo recuerda lo último
33
  with torch.no_grad():
 
10
  MAX_RESPUESTA = 200
11
 
12
 
13
+ def texto(contenido):
14
+ """El contenido de un mensaje puede venir como texto, dict o lista de partes (según la versión de Gradio)."""
15
+ if isinstance(contenido, str):
16
+ return contenido
17
+ if isinstance(contenido, dict):
18
+ return contenido.get("text") or ""
19
+ if isinstance(contenido, (list, tuple)):
20
+ return " ".join(texto(p) for p in contenido).strip()
21
+ return ""
22
+
23
+
24
  def a_mensajes(historial):
25
  """Acepta el historial de Gradio en formato de mensajes o de pares (según la versión)."""
26
  mensajes = []
27
  for item in historial or []:
28
  if isinstance(item, dict):
29
+ t = texto(item.get("content"))
30
+ if item.get("role") in ("user", "assistant") and t:
31
+ mensajes.append({"role": item["role"], "content": t})
32
  else:
33
+ usuario, asistente = texto(item[0]), texto(item[1])
34
  if usuario:
35
  mensajes.append({"role": "user", "content": usuario})
36
  if asistente:
 
39
 
40
 
41
  def responder(mensaje, historial, temperatura):
42
+ mensajes = a_mensajes(historial) + [{"role": "user", "content": texto(mensaje)}]
43
  entrada = tok.apply_chat_template(mensajes, add_generation_prompt=True, return_tensors="pt", return_dict=True)
44
  ids = entrada["input_ids"][:, -(CONTEXTO - MAX_RESPUESTA):] # solo recuerda lo último
45
  with torch.no_grad():