-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 1.54 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
from streamlit_chat import message
import json
from bardapi import Bard
with open('credentials.json', 'r') as f:
file = json.load(f)
token = file['token']
# output of prompt
def generate_response(prompt):
# prompt = 'test'
# return prompt
bard = Bard(token=token)
response = bard.get_answer(prompt)['content']
return response
# function to receive user queries
def get_text():
input_text = st.text_input("CN BOT:", "", key='Press Enter to apply')
return input_text
# Title of AI-Bot
st.title('Personal Tutoring Bot!!!')
# background of Bot
changes = '''
<style>
[data-testid = "stAppViewContainer"]
{
background: orange;
background-size:cover;
}
</style>
'''
# commit that change
st.markdown(changes, unsafe_allow_html=True)
print(st.session_state)
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
# to get input query from user
user_input = get_text()
# function calling if else
if user_input:
print(user_input)
output = generate_response(user_input)
print(output)
st.session_state['past'].append(user_input)
st.session_state['generated'].append(output)
# to store and show the live prompts of an active session
if st.session_state['generated']:
for i in range(len(st.session_state['generated']) - 1, -1, -1):
message(st.session_state['generated'][i], key=str(i))
message(st.session_state['past'][i], key="user_" + str(i), is_user=True)