Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import os
|
| 3 |
from modelo import get_chain
|
|
|
|
| 4 |
|
| 5 |
-
os.environ["OPENAI_API_KEY"] = st.secrets['OPENAI_API_KEY'] # agregada en la config de hugginface
|
| 6 |
-
|
| 7 |
-
# Initialization
|
| 8 |
-
if 'historial' not in st.session_state:
|
| 9 |
-
st.session_state['historial'] = ['🤖 Hola soy tu asistente del dia de hoy, en que te puedo ayudar']
|
| 10 |
-
|
| 11 |
-
def get_historial():
|
| 12 |
-
return st.session_state["historial"]
|
| 13 |
|
| 14 |
-
|
| 15 |
-
st.session_state["historial"].append(respuesta["query"])
|
| 16 |
-
st.session_state["historial"].append(respuesta["result"])
|
| 17 |
|
| 18 |
#Menu Visual
|
| 19 |
st.markdown("<h1 style='text-align: center; color: yellow;'>Chatbot SII</h1>", unsafe_allow_html=True) #mandar un texto en html
|
| 20 |
st.header("🤖🦾ChatBot entrenado con preguntas frecuentes del sitio del servicios de impuestos interno de Chile.")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
st.
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
st.
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from modelo import get_chain
|
| 3 |
+
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
os.environ["OPENAI_API_KEY"] = st.secrets['OPENAI_API_KEY'] # agregada en la config de hugginface
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#Menu Visual
|
| 9 |
st.markdown("<h1 style='text-align: center; color: yellow;'>Chatbot SII</h1>", unsafe_allow_html=True) #mandar un texto en html
|
| 10 |
st.header("🤖🦾ChatBot entrenado con preguntas frecuentes del sitio del servicios de impuestos interno de Chile.")
|
| 11 |
|
| 12 |
+
with st.chat_message(name="ai"): #assistant or ai
|
| 13 |
+
st.write('🤖 Hola soy tu asistente del dia de hoy, en que te puedo ayudar')
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if "mensajes" not in st.session_state:
|
| 17 |
+
st.session_state.mensajes = []
|
| 18 |
+
|
| 19 |
+
for message in st.session_state.mensajes:
|
| 20 |
+
with st.chat_message(message["role"]):
|
| 21 |
+
st.markdown(message["content"])
|
| 22 |
+
|
| 23 |
+
#Manejador del prompt, es un input y button a la vez
|
| 24 |
+
pregunta = st.chat_input("Ingresa tu pregunta")
|
| 25 |
+
chain = get_chain() #windows
|
| 26 |
+
|
| 27 |
+
if pregunta:
|
| 28 |
+
#Muestra el mensaje del usuario en el chat
|
| 29 |
+
with st.chat_message(name="human"): #assistant or ai
|
| 30 |
+
st.markdown(pregunta)
|
| 31 |
+
|
| 32 |
+
st.session_state.mensajes.append({"role" : "human", "content": pregunta})
|
| 33 |
+
respuesta = chain.invoke(pregunta)['result']
|
| 34 |
+
|
| 35 |
+
with st.chat_message(name="ai"): #assistant or ai
|
| 36 |
+
st.markdown(respuesta)
|
| 37 |
+
st.session_state.mensajes.append({"role" : "ai", "content": respuesta})
|