vmalapaka commited on
Commit
5b35737
·
verified ·
1 Parent(s): cfb720b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -10,12 +10,18 @@ from langchain.chains.conversation.memory import (ConversationBufferMemory,
10
  import tiktoken
11
  from langchain.memory import ConversationTokenBufferMemory
12
 
 
 
 
 
 
 
13
 
14
  st.set_page_config(page_title="Chat with me")
15
  st.markdown("<h1 style= 'text_align : center;'>How can I assist you? </h1>", unsafe_allow_html = True)
16
 
17
  st.sidebar.title("API")
18
- api_key = st.sidebar.text_input("Enter you API key",type = "password")
19
  summarise_button = st.sidebar.button("Summarise",key = "summarise")
20
  if summarise_button:
21
  summarise_placeholder = st.sidebar.write("Thanks for chatting \n\n"+"Hi Friend")
@@ -23,19 +29,15 @@ if summarise_button:
23
  response_container = st.container()
24
  container = st.container()
25
 
26
- if 'conversation' not in st.session_state:
27
- st.session_state['conversation'] =None
28
- if 'messages' not in st.session_state:
29
- st.session_state['messages'] =[]
30
- if 'API_Key' not in st.session_state:
31
- st.session_state['API_Key'] =''
32
 
33
- def get_response(User_input):
 
34
 
35
  if st.session_state['conversation'] is None:
36
 
37
  llm = ChatOpenAI(
38
  temperature=0,
 
39
  model_name='gpt-3.5-turbo-0125'
40
  )
41
 
@@ -57,7 +59,7 @@ with container:
57
  submit_button = st.form_submit_button(label='Send')
58
  if submit_button:
59
  st.session_state['messages'].append(user_input)
60
- model_response = get_response(user_input)
61
  st.session_state['messages'].append(model_response)
62
  st.write(st.session_state['messages'])
63
  with response_container:
 
10
  import tiktoken
11
  from langchain.memory import ConversationTokenBufferMemory
12
 
13
+ if 'conversation' not in st.session_state:
14
+ st.session_state['conversation'] =None
15
+ if 'messages' not in st.session_state:
16
+ st.session_state['messages'] =[]
17
+ if 'API_Key' not in st.session_state:
18
+ st.session_state['API_Key'] =''
19
 
20
  st.set_page_config(page_title="Chat with me")
21
  st.markdown("<h1 style= 'text_align : center;'>How can I assist you? </h1>", unsafe_allow_html = True)
22
 
23
  st.sidebar.title("API")
24
+ st.session_state['API_Key'] = st.sidebar.text_input("Enter you API key",type = "password")
25
  summarise_button = st.sidebar.button("Summarise",key = "summarise")
26
  if summarise_button:
27
  summarise_placeholder = st.sidebar.write("Thanks for chatting \n\n"+"Hi Friend")
 
29
  response_container = st.container()
30
  container = st.container()
31
 
 
 
 
 
 
 
32
 
33
+
34
+ def get_response(User_input,api_key):
35
 
36
  if st.session_state['conversation'] is None:
37
 
38
  llm = ChatOpenAI(
39
  temperature=0,
40
+ openai_api_key = api_key,
41
  model_name='gpt-3.5-turbo-0125'
42
  )
43
 
 
59
  submit_button = st.form_submit_button(label='Send')
60
  if submit_button:
61
  st.session_state['messages'].append(user_input)
62
+ model_response = get_response(user_input,st.session_state['API_Key'])
63
  st.session_state['messages'].append(model_response)
64
  st.write(st.session_state['messages'])
65
  with response_container: