Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,12 +44,13 @@ def validate_input(user_input):
|
|
| 44 |
return False, "Input cannot be empty."
|
| 45 |
return True, ""
|
| 46 |
|
| 47 |
-
def get_response(user_input, api_url=API_URL):
|
| 48 |
is_valid, error_message = validate_input(user_input)
|
| 49 |
if not is_valid:
|
| 50 |
return error_message
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
response = query(payload, api_url)
|
| 54 |
return response.get('text', "Error: No API response.")
|
| 55 |
|
|
@@ -100,62 +101,13 @@ with st.form(key='my_form', clear_on_submit=True):
|
|
| 100 |
submit_button = st.form_submit_button(label='Send')
|
| 101 |
|
| 102 |
if submit_button and user_input:
|
| 103 |
-
output = get_response(user_input)
|
| 104 |
st.session_state['past'].append(user_input)
|
| 105 |
st.session_state['generated'].append(output)
|
|
|
|
| 106 |
|
| 107 |
# Mostrar el historial del chat
|
| 108 |
with chat_container.container():
|
| 109 |
for i in range(len(st.session_state['generated'])):
|
| 110 |
st.write(f"**User:** {st.session_state['past'][i]}")
|
| 111 |
st.write(f"**Bot:** {st.session_state['generated'][i]}")
|
| 112 |
-
|
| 113 |
-
# Alternar entre modo claro y oscuro
|
| 114 |
-
if 'dark_mode' not in st.session_state:
|
| 115 |
-
st.session_state['dark_mode'] = False
|
| 116 |
-
|
| 117 |
-
def toggle_dark_mode():
|
| 118 |
-
st.session_state['dark_mode'] = not st.session_state['dark_mode']
|
| 119 |
-
|
| 120 |
-
st.sidebar.button("Toggle Dark Mode", on_click=toggle_dark_mode)
|
| 121 |
-
|
| 122 |
-
if st.session_state['dark_mode']:
|
| 123 |
-
st.markdown(
|
| 124 |
-
"""
|
| 125 |
-
<style>
|
| 126 |
-
.main {
|
| 127 |
-
background-color: #0e1117;
|
| 128 |
-
color: #c9d1d9;
|
| 129 |
-
}
|
| 130 |
-
</style>
|
| 131 |
-
""",
|
| 132 |
-
unsafe_allow_html=True
|
| 133 |
-
)
|
| 134 |
-
else:
|
| 135 |
-
st.markdown(
|
| 136 |
-
"""
|
| 137 |
-
<style>
|
| 138 |
-
.main {
|
| 139 |
-
background-color: #ffffff;
|
| 140 |
-
color: #000000;
|
| 141 |
-
}
|
| 142 |
-
</style>
|
| 143 |
-
""",
|
| 144 |
-
unsafe_allow_html=True
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
st.markdown(
|
| 149 |
-
"""
|
| 150 |
-
<style>
|
| 151 |
-
.stTextInput {
|
| 152 |
-
position: fixed;
|
| 153 |
-
bottom: 0;
|
| 154 |
-
width: 100%;
|
| 155 |
-
padding: 10px;
|
| 156 |
-
box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
|
| 157 |
-
}
|
| 158 |
-
</style>
|
| 159 |
-
""",
|
| 160 |
-
unsafe_allow_html=True
|
| 161 |
-
)
|
|
|
|
| 44 |
return False, "Input cannot be empty."
|
| 45 |
return True, ""
|
| 46 |
|
| 47 |
+
def get_response(user_input, history, api_url=API_URL):
|
| 48 |
is_valid, error_message = validate_input(user_input)
|
| 49 |
if not is_valid:
|
| 50 |
return error_message
|
| 51 |
|
| 52 |
+
# Incluir el historial en el payload
|
| 53 |
+
payload = {"question": user_input, "history": history}
|
| 54 |
response = query(payload, api_url)
|
| 55 |
return response.get('text', "Error: No API response.")
|
| 56 |
|
|
|
|
| 101 |
submit_button = st.form_submit_button(label='Send')
|
| 102 |
|
| 103 |
if submit_button and user_input:
|
| 104 |
+
output = get_response(user_input, st.session_state['history'])
|
| 105 |
st.session_state['past'].append(user_input)
|
| 106 |
st.session_state['generated'].append(output)
|
| 107 |
+
st.session_state['history'].append({"user": user_input, "bot": output})
|
| 108 |
|
| 109 |
# Mostrar el historial del chat
|
| 110 |
with chat_container.container():
|
| 111 |
for i in range(len(st.session_state['generated'])):
|
| 112 |
st.write(f"**User:** {st.session_state['past'][i]}")
|
| 113 |
st.write(f"**Bot:** {st.session_state['generated'][i]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|