SrGuanche commited on
Commit
bd98599
·
verified ·
1 Parent(s): d3b9a6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -13,22 +13,30 @@ def answer(history, message):
13
  if not message.strip():
14
  return history, ""
15
 
16
- # Construir contexto
17
- context = ""
 
 
 
 
 
 
 
18
  for user, bot in history[-6:]:
19
  context += f"Usuario: {user}\nIA: {bot}\n"
20
  context += f"Usuario: {message}\nIA:"
21
 
22
- # Generar respuesta en español
23
  output = generator(
24
  context,
25
- max_new_tokens=100,
26
  do_sample=True,
27
- top_k=40,
28
- top_p=0.9,
29
- temperature=0.7
30
  )[0]["generated_text"]
31
 
 
32
  if "IA:" in output:
33
  response = output.split("IA:")[-1].strip()
34
  else:
@@ -40,7 +48,7 @@ def answer(history, message):
40
 
41
  # --- Interfaz Gradio ---
42
  with gr.Blocks() as demo:
43
- gr.Markdown("# 🤖 Chatbot en Español (Ligero y Estable)")
44
  chat = gr.Chatbot()
45
  msg = gr.Textbox(placeholder="Escribe tu mensaje…")
46
  clear_btn = gr.Button("Limpiar")
 
13
  if not message.strip():
14
  return history, ""
15
 
16
+ # Prompt inicial para orientar la conversación
17
+ system_prompt = (
18
+ "Eres un asistente virtual que siempre responde en español de manera lógica, "
19
+ "clara y coherente. No hagas listas de palabras ni saludes en otros idiomas. "
20
+ "Responde de forma natural y breve.\n"
21
+ )
22
+
23
+ # Construir contexto con historial
24
+ context = system_prompt
25
  for user, bot in history[-6:]:
26
  context += f"Usuario: {user}\nIA: {bot}\n"
27
  context += f"Usuario: {message}\nIA:"
28
 
29
+ # Generar respuesta
30
  output = generator(
31
  context,
32
+ max_new_tokens=50, # Limitar longitud para evitar listas
33
  do_sample=True,
34
+ top_k=20, # Más centrado en palabras probables
35
+ top_p=0.8, # Reduce creatividad excesiva
36
+ temperature=0.6 # Más determinista
37
  )[0]["generated_text"]
38
 
39
+ # Extraer la respuesta limpia
40
  if "IA:" in output:
41
  response = output.split("IA:")[-1].strip()
42
  else:
 
48
 
49
  # --- Interfaz Gradio ---
50
  with gr.Blocks() as demo:
51
+ gr.Markdown("# 🤖 Chatbot en Español - Conversaciones Lógicas")
52
  chat = gr.Chatbot()
53
  msg = gr.Textbox(placeholder="Escribe tu mensaje…")
54
  clear_btn = gr.Button("Limpiar")