|
import requests |
|
import streamlit as st |
|
import time |
|
|
|
st.title("Rasa Chatbot Interface") |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if user_input := st.chat_input("What is up?"): |
|
|
|
st.session_state.messages.append({"role": "user", "content": user_input}) |
|
|
|
with st.chat_message("user"): |
|
st.markdown(user_input) |
|
|
|
|
|
payload = {"sender": "user", "message": user_input} |
|
response = requests.post('https://omdenalc-omdena-ng-lagos-chatbot-model.hf.space/webhooks/rest/webhook', json=payload) |
|
bot_reply = response.json() |
|
|
|
|
|
assistant_response = bot_reply[0]["text"] |
|
|
|
|
|
with st.chat_message("assistant"): |
|
message_placeholder = st.empty() |
|
full_response = "" |
|
|
|
for chunk in assistant_response.split(): |
|
full_response += chunk + " " |
|
time.sleep(0.05) |
|
|
|
message_placeholder.markdown(full_response + "β") |
|
message_placeholder.markdown(full_response) |
|
|
|
|
|
st.session_state.messages.append({"role": "assistant", "content": full_response}) |
|
|
|
|
|
with st.expander("Debug"): |
|
if st.button("Show Debug Info"): |
|
url = 'https://omdenalc-omdena-ng-lagos-chatbot-model.hf.space' |
|
request_ids = ['/status', '/version'] |
|
results = [requests.get(url+request_id).json() for request_id in request_ids] |
|
st.write(results) |
|
else: |
|
st.write("") |
|
|
|
|
|
|