Spaces:
Runtime error
Runtime error
| 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}; |