iamrobotbear commited on
Commit
9b44f60
1 Parent(s): 17d7a6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -44
app.py CHANGED
@@ -4,69 +4,35 @@ import streamlit as st
4
  import os
5
  from PIL import Image
6
 
7
- topics = {
8
- 'Standardized testing in education': '266',
9
- 'Ethical implications of genetic editing': '267',
10
- 'Social media and mental health': '268',
11
- 'discus': '45'
12
- }
13
-
14
  def launch_bot():
15
- def generate_response(question, cfg):
16
  response = vq.submit_query(question)
17
  return response
18
 
19
  def reset():
20
- st.session_state.messages = [{"role": "assistant", "content": "Please make your opening statement.", "avatar": '🦖'}]
21
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
22
 
23
  if 'cfg' not in st.session_state:
24
  cfg = OmegaConf.create({
25
  'customer_id': str(os.environ['VECTARA_CUSTOMER_ID']),
26
- 'corpus_id': list(topics.values())[0],
27
  'api_key': str(os.environ['VECTARA_API_KEY']),
28
  'prompt_name': 'vectara-experimental-summary-ext-2023-12-11-large',
29
  })
30
  st.session_state.cfg = cfg
31
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
32
 
33
- st.session_state.current_human_role = None
34
- st.session_state.current_topic = None
35
- st.session_state.style = None
36
-
37
  cfg = st.session_state.cfg
38
  vq = st.session_state.vq
39
- st.set_page_config(page_title="Debate Bot", layout="wide")
40
-
41
 
42
- # left side content
43
  with st.sidebar:
44
  image = Image.open('Vectara-logo.png')
45
  st.image(image, width=250)
46
- st.markdown(f"## Welcome to Debate Bot.\n\n\n")
47
-
48
- role_options = ['in opposition to', 'in support of']
49
- cfg.human_role = st.selectbox('You (the human) are:', role_options)
50
- cfg.bot_role = role_options[1] if cfg.human_role == role_options[0] else role_options[0]
51
- if st.session_state.current_human_role != cfg.human_role:
52
- st.session_state.current_human_role = cfg.human_role
53
- reset()
54
 
55
- topic_options = list(topics.keys())
56
- cfg.topic = st.selectbox('The topic:', topic_options)
57
- vq.corpus_id = topics[cfg.topic]
58
- if st.session_state.current_topic != cfg.topic:
59
- st.session_state.current_topic = cfg.topic
60
- reset()
61
-
62
- st.markdown("\n")
63
- debate_styles = ['Lincoln-Douglas', 'Spontaneous Argumentation', 'Parliamentary debates']
64
- cfg.style = st.selectbox('Debate Style:', debate_styles)
65
- if st.session_state.style != cfg.style:
66
- st.session_state.style = cfg.style
67
- reset()
68
-
69
- st.markdown("\n\n")
70
  if st.button('Start Over'):
71
  reset()
72
 
@@ -78,7 +44,6 @@ def launch_bot():
78
  )
79
  st.markdown("---")
80
 
81
-
82
  if "messages" not in st.session_state.keys():
83
  reset()
84
 
@@ -96,9 +61,8 @@ def launch_bot():
96
  # Generate a new response if last message is not from assistant
97
  if st.session_state.messages[-1]["role"] != "assistant":
98
  with st.chat_message("assistant", avatar='🤖'):
99
- stream = generate_response(prompt, cfg)
100
- with st.spinner('Thinking...'):
101
- response = st.write_stream(stream)
102
  message = {"role": "assistant", "content": response, "avatar": '🤖'}
103
  st.session_state.messages.append(message)
104
 
 
4
  import os
5
  from PIL import Image
6
 
 
 
 
 
 
 
 
7
  def launch_bot():
8
+ def generate_response(question):
9
  response = vq.submit_query(question)
10
  return response
11
 
12
  def reset():
13
+ st.session_state.messages = [{"role": "assistant", "content": "Please ask your question about drink names.", "avatar": '🦖'}]
14
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
15
 
16
  if 'cfg' not in st.session_state:
17
  cfg = OmegaConf.create({
18
  'customer_id': str(os.environ['VECTARA_CUSTOMER_ID']),
19
+ 'corpus_id': '45', # Fixed corpus ID for drink names
20
  'api_key': str(os.environ['VECTARA_API_KEY']),
21
  'prompt_name': 'vectara-experimental-summary-ext-2023-12-11-large',
22
  })
23
  st.session_state.cfg = cfg
24
  st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
25
 
 
 
 
 
26
  cfg = st.session_state.cfg
27
  vq = st.session_state.vq
28
+ st.set_page_config(page_title="Drink Name Query Bot", layout="wide")
 
29
 
30
+ # Left side content
31
  with st.sidebar:
32
  image = Image.open('Vectara-logo.png')
33
  st.image(image, width=250)
34
+ st.markdown(f"## Welcome to Drink Name Query Bot.\n\n\n")
 
 
 
 
 
 
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  if st.button('Start Over'):
37
  reset()
38
 
 
44
  )
45
  st.markdown("---")
46
 
 
47
  if "messages" not in st.session_state.keys():
48
  reset()
49
 
 
61
  # Generate a new response if last message is not from assistant
62
  if st.session_state.messages[-1]["role"] != "assistant":
63
  with st.chat_message("assistant", avatar='🤖'):
64
+ response = generate_response(prompt)
65
+ st.write(response)
 
66
  message = {"role": "assistant", "content": response, "avatar": '🤖'}
67
  st.session_state.messages.append(message)
68