Spaces:
Runtime error
Runtime error
Download modules/chat.py from Garimind/GariGariMind-Frontend-Memory-Engine: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/chat.py
- Command line
-
hf download hf://spaces/Garimind/GariGariMind-Frontend-Memory-Engine/modules/chat.py
-
curl -L -o chat.py https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/chat.py
2.07 kB
| 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() | |