File size: 1,364 Bytes
0400f01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02640bf
0400f01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import requests
import json

st.title("Rasa Chatbot Interface")

# Initialize or get the chat history
if 'chat_history' not in st.session_state:
    st.session_state.chat_history = []

with st.form(key='chat_form'):
    user_input = st.text_input("You:")
    
    # You can submit the form by pressing enter or by clicking the button
    submitted = st.form_submit_button("Send")
    
    if submitted and user_input:
        payload = {"sender": "user", "message": user_input}
        response = requests.post('https://pvanand-rasa-moodbot.hf.space/webhooks/rest/webhook', json=payload)
        bot_reply = response.json()

        # Append the user message and bot reply to the chat history
        st.session_state.chat_history.append(("You:", user_input, True))
        st.session_state.chat_history.append(("Bot:", bot_reply[0]['text'], False))

# Display the chat history
for message in st.session_state.chat_history:
    sender, text, is_user = message
    alignment = "right" if is_user else "left"
    background_color = "#f5f5f5" # light background color
    text_color = "#333333" # dark text color
    
    st.markdown(
        f"<div style='text-align: {alignment};padding: 10px; margin: 5px; border-radius: 5px;'>{text}</div>",
        unsafe_allow_html=True,
    )
# background-color: {background_color}; color: {text_color};