-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (27 loc) · 1.15 KB
/
app.py
File metadata and controls
33 lines (27 loc) · 1.15 KB
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
import streamlit as st
import requests
st.title('Rasa Chatbot Demo')
user_input = st.text_input('Enter your message:')
submit_button = st.button('Send')
if submit_button and user_input:
try:
# Send user message to Rasa server
rasa_url = "http://localhost:5056/webhook"
response = requests.post(rasa_url, json={'sender': 'user', 'message': user_input})
print(response) # Print the response for debugging
# Handle response
if response.status_code == 200:
bot_responses = response.json()
if bot_responses is not None:
for bot_response in bot_responses:
st.text(f"Bot: {bot_response['text']}")
else:
st.error("Empty response from Rasa server.")
else:
st.error(f"Failed to get response from Rasa. Status code: {response.status_code}")
except requests.exceptions.ConnectionError as e:
st.error(f"Connection error: {e}")
except requests.exceptions.RequestException as e:
st.error(f"Request error: {e}")
except Exception as e:
st.error(f"An error occurred: {e}")