olamidegoriola pvanand commited on
Commit
11182eb
1 Parent(s): 91956e8

Add sheets as a database for storing user conversation (#12)

Browse files

- Add sheets as a database for storing user conversation (26fddab8b21e6529998afbe5e8dbb2a1ee665af0)


Co-authored-by: Anand <[email protected]>

Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -2,9 +2,9 @@ import requests
2
  import streamlit as st
3
  import time
4
 
5
- st.title("Rasa Chatbot Interface")
6
 
7
- # Change api url to yours here
8
  url = 'https://omdena-lc-omdena-ng-lagos-chatbot-model.hf.space'
9
 
10
  # Initialize chat history
@@ -32,11 +32,9 @@ if user_input := st.chat_input("What is up?"):
32
  # Extract assistant response
33
  if bot_reply !=[]:
34
  assistant_response = bot_reply[0]["text"]
35
- # Handle empty api responses
36
  else:
37
  assistant_response = 'API request returned with an empty list []. Please continue with a different question'
38
 
39
-
40
  # Display assistant response in chat message container
41
  with st.chat_message("assistant"):
42
  message_placeholder = st.empty()
@@ -51,8 +49,24 @@ if user_input := st.chat_input("What is up?"):
51
 
52
  # Add assistant response to chat history
53
  st.session_state.messages.append({"role": "assistant", "content": full_response})
54
-
55
- # Add debug button to display RASA version, Model Name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  with st.expander("Debug"):
57
  if st.button("Show Debug Info"):
58
  request_ids = ['/status', '/version']
@@ -62,4 +76,3 @@ with st.expander("Debug"):
62
  st.write("")
63
 
64
 
65
-
 
2
  import streamlit as st
3
  import time
4
 
5
+ st.title("Omdena Chatbot Interface")
6
 
7
+ # Edit API url here
8
  url = 'https://omdena-lc-omdena-ng-lagos-chatbot-model.hf.space'
9
 
10
  # Initialize chat history
 
32
  # Extract assistant response
33
  if bot_reply !=[]:
34
  assistant_response = bot_reply[0]["text"]
 
35
  else:
36
  assistant_response = 'API request returned with an empty list []. Please continue with a different question'
37
 
 
38
  # Display assistant response in chat message container
39
  with st.chat_message("assistant"):
40
  message_placeholder = st.empty()
 
49
 
50
  # Add assistant response to chat history
51
  st.session_state.messages.append({"role": "assistant", "content": full_response})
52
+
53
+ # Save to google sheet
54
+ # Deployed web app URL for writing google sheets
55
+ webhook_url = "https://script.google.com/macros/s/AKfycbzhikyq7IduuEPGmrvcmJV9YlziiVyBysQ_oYf7lOzF8w9zg--BI2S_5cLuftp0pKqy/exec"
56
+ action = "?action=addData"
57
+ # Data to send
58
+ data = {
59
+ "user": user_input,
60
+ "bot": assistant_response
61
+ }
62
+ try:
63
+ # Send POST request to the webhook URL
64
+ response = requests.post(webhook_url + action, json=data)
65
+ except:
66
+ pass
67
+
68
+
69
+ # Add debug button to display RASA version, Model Name
70
  with st.expander("Debug"):
71
  if st.button("Show Debug Info"):
72
  request_ids = ['/status', '/version']
 
76
  st.write("")
77
 
78