Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +26 -12
streamlit_app.py
CHANGED
|
@@ -1,17 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
st.set_page_config(layout="
|
| 5 |
-
st.title("
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
st.
|
| 11 |
-
|
| 12 |
-
st.metric("Utilizadores", 120)
|
| 13 |
-
st.metric("Projetos", 8)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import time
|
| 3 |
|
| 4 |
+
st.set_page_config(page_title="Meu Chatbot", page_icon="💬", layout="centered")
|
| 5 |
+
st.title("💬 Meu Chatbot")
|
| 6 |
|
| 7 |
+
if "messages" not in st.session_state:
|
| 8 |
+
st.session_state.messages = [
|
| 9 |
+
{"role": "assistant", "content": "Olá! Sou o teu chatbot. Em que posso ajudar?"}
|
| 10 |
+
]
|
| 11 |
|
| 12 |
+
for message in st.session_state.messages:
|
| 13 |
+
with st.chat_message(message["role"]):
|
| 14 |
+
st.markdown(message["content"])
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
def gerar_resposta(prompt):
|
| 17 |
+
resposta = f"Tu disseste: {prompt}. Isto é uma resposta de teste mais bonita."
|
| 18 |
+
for palavra in resposta.split():
|
| 19 |
+
yield palavra + " "
|
| 20 |
+
time.sleep(0.03)
|
| 21 |
+
|
| 22 |
+
if prompt := st.chat_input("Escreve a tua mensagem..."):
|
| 23 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 24 |
+
|
| 25 |
+
with st.chat_message("user"):
|
| 26 |
+
st.markdown(prompt)
|
| 27 |
+
|
| 28 |
+
with st.chat_message("assistant"):
|
| 29 |
+
resposta_final = st.write_stream(gerar_resposta(prompt))
|
| 30 |
+
|
| 31 |
+
st.session_state.messages.append({"role": "assistant", "content": resposta_final})
|