Spaces:
Sleeping
Sleeping
Rohan Kumar Singh
commited on
Commit
·
12ef87a
1
Parent(s):
d301bcb
mongodb testing
Browse files
app.py
CHANGED
@@ -96,6 +96,15 @@ def generate_response(question):
|
|
96 |
import streamlit as st
|
97 |
from streamlit_chat import message
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
st.title(":red[_Sarcastic_] Chatbot")
|
100 |
|
101 |
if 'generated' not in st.session_state:
|
@@ -119,6 +128,7 @@ with container:
|
|
119 |
user_input = st.text_input("You:", key='input',placeholder="Disclaimer: Be careful with punctuations like , ? . ! \" and IT WILL CUSS YOU")
|
120 |
submit_button = st.form_submit_button(label='Send',use_container_width=True)
|
121 |
clear_button = st.button("Clear Conversation", key="clear",use_container_width=True)
|
|
|
122 |
# reset everything
|
123 |
if clear_button:
|
124 |
st.session_state['generated'] = []
|
@@ -127,6 +137,17 @@ with container:
|
|
127 |
{"role": "system", "content": "You are a helpful assistant."}
|
128 |
]
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
if submit_button and user_input:
|
131 |
output = generate_response(user_input)
|
132 |
st.session_state['past'].append(user_input)
|
|
|
96 |
import streamlit as st
|
97 |
from streamlit_chat import message
|
98 |
|
99 |
+
|
100 |
+
from pymongo.mongo_client import MongoClient
|
101 |
+
from pymongo.server_api import ServerApi
|
102 |
+
|
103 |
+
uri = "mongodb+srv://rohank587:zaqxswcdevfr@rkcluster.e3fpzja.mongodb.net/?retryWrites=true&w=majority"
|
104 |
+
|
105 |
+
# Create a new client and connect to the server
|
106 |
+
client = MongoClient(uri, server_api=ServerApi('1'))
|
107 |
+
|
108 |
st.title(":red[_Sarcastic_] Chatbot")
|
109 |
|
110 |
if 'generated' not in st.session_state:
|
|
|
128 |
user_input = st.text_input("You:", key='input',placeholder="Disclaimer: Be careful with punctuations like , ? . ! \" and IT WILL CUSS YOU")
|
129 |
submit_button = st.form_submit_button(label='Send',use_container_width=True)
|
130 |
clear_button = st.button("Clear Conversation", key="clear",use_container_width=True)
|
131 |
+
save_button = st.button("Save Conversation", key="save",use_container_width=True)
|
132 |
# reset everything
|
133 |
if clear_button:
|
134 |
st.session_state['generated'] = []
|
|
|
137 |
{"role": "system", "content": "You are a helpful assistant."}
|
138 |
]
|
139 |
|
140 |
+
if save_button:
|
141 |
+
# Send a ping to confirm a successful connection
|
142 |
+
try:
|
143 |
+
client.admin.command('ping')
|
144 |
+
st.write("Pinged your deployment. You successfully connected to MongoDB!")
|
145 |
+
except Exception as e:
|
146 |
+
st.write(e)
|
147 |
+
info=client['rohank']['table1']
|
148 |
+
info.insert_one({"message":"first time"})
|
149 |
+
|
150 |
+
|
151 |
if submit_button and user_input:
|
152 |
output = generate_response(user_input)
|
153 |
st.session_state['past'].append(user_input)
|