Spaces:
Sleeping
Sleeping
Rohan Kumar Singh
commited on
Commit
·
f009f84
1
Parent(s):
57c9a1d
added download feature
Browse files
app.py
CHANGED
@@ -93,6 +93,7 @@ def generate_response(question):
|
|
93 |
|
94 |
return "".join(preds)
|
95 |
|
|
|
96 |
import streamlit as st
|
97 |
from streamlit_chat import message
|
98 |
|
@@ -125,10 +126,18 @@ container = st.container()
|
|
125 |
|
126 |
with container:
|
127 |
with st.form(key='my_form', clear_on_submit=True):
|
128 |
-
user_input = st.text_input("You:", key='input',placeholder="Disclaimer: Be careful with punctuations like , ? . ! \"
|
129 |
submit_button = st.form_submit_button(label='Send',use_container_width=True)
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
# reset everything
|
133 |
if clear_button:
|
134 |
st.session_state['generated'] = []
|
@@ -141,12 +150,18 @@ with container:
|
|
141 |
# Send a ping to confirm a successful connection
|
142 |
try:
|
143 |
client.admin.command('ping')
|
144 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
except Exception as e:
|
146 |
-
st.
|
147 |
-
|
148 |
-
info.insert_one({"message":"first time"})
|
149 |
-
|
150 |
|
151 |
if submit_button and user_input:
|
152 |
output = generate_response(user_input)
|
|
|
93 |
|
94 |
return "".join(preds)
|
95 |
|
96 |
+
import uuid
|
97 |
import streamlit as st
|
98 |
from streamlit_chat import message
|
99 |
|
|
|
126 |
|
127 |
with container:
|
128 |
with st.form(key='my_form', clear_on_submit=True):
|
129 |
+
user_input = st.text_input("You:", key='input',placeholder="Disclaimer: Be careful with punctuations like , ? . ! \"")
|
130 |
submit_button = st.form_submit_button(label='Send',use_container_width=True)
|
131 |
+
col1,col2=st.columns(2)
|
132 |
+
with col1:
|
133 |
+
clear_button = st.button("Clear Conversation", key="clear",use_container_width=True)
|
134 |
+
with col2:
|
135 |
+
save_button = st.button("Save Conversation", key="save",use_container_width=True)
|
136 |
+
down_id = st.text_input('Enter ID to download chat',placeholder="Message ID")
|
137 |
+
if down_id:
|
138 |
+
info=client['rohank']['table1']
|
139 |
+
data=info.find_one({'message_id':down_id})
|
140 |
+
down_button = st.download_button('Download chat', "\n".join(data['message']),file_name="sar_chat.txt")
|
141 |
# reset everything
|
142 |
if clear_button:
|
143 |
st.session_state['generated'] = []
|
|
|
150 |
# Send a ping to confirm a successful connection
|
151 |
try:
|
152 |
client.admin.command('ping')
|
153 |
+
st.success("Pinged your deployment. You successfully connected to MongoDB! Saved Successfully.")
|
154 |
+
info=client['rohank']['table1']
|
155 |
+
chats=list([])
|
156 |
+
for i in range(len(st.session_state['generated'])):
|
157 |
+
chats.append("You: "+st.session_state['past'][i])
|
158 |
+
chats.append("Bot: "+st.session_state['generated'][i])
|
159 |
+
id=uuid.uuid4()
|
160 |
+
info.insert_one({"message_id":str(id),"message":chats})
|
161 |
+
st.success("Copy this id "+str(id)+" for downloading saved chat anytime anywhere and then paste it down below!")
|
162 |
except Exception as e:
|
163 |
+
st.error("Can't connect to MongoDB. Save Failed.")
|
164 |
+
|
|
|
|
|
165 |
|
166 |
if submit_button and user_input:
|
167 |
output = generate_response(user_input)
|