Spaces:
Runtime error
Runtime error
File size: 2,074 Bytes
ec7d0cb a473006 ec7d0cb a473006 ec7d0cb a473006 907e7ca a473006 907e7ca 482f5c1 907e7ca 482f5c1 a473006 907e7ca a473006 907e7ca a473006 907e7ca a473006 907e7ca a473006 907e7ca 482f5c1 907e7ca | 1 2 3 4 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import streamlit as st
from modules.utils.parser_intent import parse_task_command
from modules.procesadores.tareas import TaskProcessor
class ChatInterface:
def __init__(self, ctx):
self.user = ctx
self.tasker = TaskProcessor(ctx)
def render(self):
st.header("馃挰 Chat GariMind")
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# Pintamos el hist贸rico
for entry in st.session_state.chat_history:
role, text = entry["role"], entry["text"]
if role == "user":
st.markdown(f"**T煤:** {text}")
else:
st.markdown(f"**GariMind:** {text}")
# Creamos un form para input+bot贸n, as铆 tras el submit el input se borra solo
with st.form("chat_form", clear_on_submit=True):
prompt = st.text_input("Escribe tu mensaje", key="chat_input")
ok = st.form_submit_button("Enviar")
if ok and prompt:
# 1) a帽adimos el mensaje del usuario al hist贸rico
st.session_state.chat_history.append({"role": "user", "text": prompt})
# 2) intentamos parsear comando de tarea
intent = parse_task_command(prompt)
if intent:
action = intent["action"]
task = intent["task"]
if action == "create_task":
msg = self.tasker.create_task(task)
elif action == "update_task":
msg = self.tasker.update_task(task)
elif action == "complete_task":
msg = self.tasker.complete_task(task.get("id"))
else:
msg = "No he entendido la acci贸n."
else:
msg = f"Recib铆: 芦{prompt}禄"
# 3) a帽adimos respuesta de GariMind al hist贸rico
st.session_state.chat_history.append({"role": "bot", "text": msg})
# 4) forzamos rerun para que se renderice el hist贸rico actualizado
st.experimental_rerun()
|