Spaces:
Build error
Build error
Rajesh G
commited on
Commit
·
64d99bb
1
Parent(s):
2b58a2f
Updated chat sequence
Browse files- app.py +2 -1
- chat_app.py +0 -65
app.py
CHANGED
|
@@ -40,8 +40,9 @@ user_input = st.text_input("Type your message here:", key="user_input")
|
|
| 40 |
if st.button("Send"):
|
| 41 |
if user_input:
|
| 42 |
response = call_web_service(user_input)
|
| 43 |
-
chat_history.append("You :" + " " + user_input)
|
| 44 |
chat_history.append("DocChat :" + " " + response["message"])
|
|
|
|
|
|
|
| 45 |
for message in chat_history:
|
| 46 |
format_sql_insert = 'INSERT INTO messages (message, unique_id) VALUES ("{value}","{uniqueid}")'.format(value=message,uniqueid=st.session_state['session_unique_id'])
|
| 47 |
print("DEBUG: " + format_sql_insert)
|
|
|
|
| 40 |
if st.button("Send"):
|
| 41 |
if user_input:
|
| 42 |
response = call_web_service(user_input)
|
|
|
|
| 43 |
chat_history.append("DocChat :" + " " + response["message"])
|
| 44 |
+
chat_history.append("You :" + " " + user_input)
|
| 45 |
+
|
| 46 |
for message in chat_history:
|
| 47 |
format_sql_insert = 'INSERT INTO messages (message, unique_id) VALUES ("{value}","{uniqueid}")'.format(value=message,uniqueid=st.session_state['session_unique_id'])
|
| 48 |
print("DEBUG: " + format_sql_insert)
|
chat_app.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
-
import json
|
| 4 |
-
import sqlite3
|
| 5 |
-
import datetime
|
| 6 |
-
import yaml
|
| 7 |
-
|
| 8 |
-
chat_history = []
|
| 9 |
-
#"st.session_state object", st.session_state
|
| 10 |
-
|
| 11 |
-
with open('config.yaml', 'r') as file:
|
| 12 |
-
config = yaml.safe_load(file)
|
| 13 |
-
|
| 14 |
-
docchat_engine_url = config['docchat-engine']['url']
|
| 15 |
-
|
| 16 |
-
conn = sqlite3.connect('message.db')
|
| 17 |
-
c = conn.cursor()
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#Get unique id from database and set the session unique id
|
| 21 |
-
if 'session_unique_id' not in st.session_state:
|
| 22 |
-
#Insert timestamp of the request, the unique id is autogenerated at the table level.
|
| 23 |
-
c.execute("INSERT INTO SESSION (TIMESTAMP) VALUES('{timestamp_value}')".format(timestamp_value=datetime.datetime.now()))
|
| 24 |
-
conn.commit()
|
| 25 |
-
|
| 26 |
-
#Fetch the autogenerated uniqueid from table (autoincremented number)
|
| 27 |
-
c.execute("SELECT UNIQUE_ID FROM SESSION ORDER BY UNIQUE_ID DESC LIMIT 1")
|
| 28 |
-
for tmp_select_return_msg in c.fetchone():
|
| 29 |
-
unique_id_from_db = tmp_select_return_msg
|
| 30 |
-
st.session_state['session_unique_id'] = unique_id_from_db
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def call_web_service(message):
|
| 34 |
-
response = requests.post('{value_url}/chat/'.format(value_url=docchat_engine_url), json={'text': message})
|
| 35 |
-
return response.json()
|
| 36 |
-
|
| 37 |
-
st.title('Chat Interface')
|
| 38 |
-
|
| 39 |
-
user_input = st.text_input("Type your message here:", key="user_input")
|
| 40 |
-
if st.button("Send"):
|
| 41 |
-
if user_input:
|
| 42 |
-
response = call_web_service(user_input)
|
| 43 |
-
chat_history.append("You :" + " " + user_input)
|
| 44 |
-
chat_history.append("DocChat :" + " " + response["message"])
|
| 45 |
-
for message in chat_history:
|
| 46 |
-
format_sql_insert = 'INSERT INTO messages (message, unique_id) VALUES ("{value}","{uniqueid}")'.format(value=message,uniqueid=st.session_state['session_unique_id'])
|
| 47 |
-
print("DEBUG: " + format_sql_insert)
|
| 48 |
-
c.execute(format_sql_insert)
|
| 49 |
-
conn.commit()
|
| 50 |
-
|
| 51 |
-
c.execute("Select message from messages where unique_id = {value_unique_id} order by id desc".format(value_unique_id=st.session_state['session_unique_id']))
|
| 52 |
-
msg_from_db = c.fetchall()
|
| 53 |
-
|
| 54 |
-
for op_message in msg_from_db:
|
| 55 |
-
st.write(op_message[0])
|
| 56 |
-
|
| 57 |
-
if 'button_clicked' not in st.session_state:
|
| 58 |
-
st.session_state.button_clicked = False
|
| 59 |
-
|
| 60 |
-
if st.sidebar.button('Load Chat'):
|
| 61 |
-
st.session_state.button_clicked = True
|
| 62 |
-
|
| 63 |
-
if st.session_state.button_clicked:
|
| 64 |
-
response = requests.post('{value_url}/loadvector/'.format(value_url=docchat_engine_url), json={"text": "_chat"})
|
| 65 |
-
st.write('Context Loaded')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|