|
import requests |
|
import streamlit as st |
|
import random |
|
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() |
|
|
|
|
|
with st.chat_message("assistant"): |
|
message_placeholder = st.empty() |
|
full_response = "" |
|
assistant_response = random.choice(bot_reply)["text"] |
|
|
|
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}) |