david-oplatka commited on
Commit
0d97318
·
verified ·
1 Parent(s): efae089

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -49
app.py CHANGED
@@ -11,57 +11,56 @@ def isTrue(x) -> bool:
11
  return x
12
  return x.strip().lower() == 'true'
13
 
14
- with streamlit_analytics.track():
15
- def launch_bot():
16
- def generate_response(question):
17
- response = vq.submit_query(question)
18
- return response
19
-
20
- def generate_streaming_response(question):
21
- response = vq.submit_query_streaming(question)
22
- return response
23
-
24
- if 'cfg' not in st.session_state:
25
- corpus_ids = str(os.environ['corpus_ids']).split(',')
26
- cfg = OmegaConf.create({
27
- 'customer_id': str(os.environ['customer_id']),
28
- 'corpus_ids': corpus_ids,
29
- 'api_key': str(os.environ['api_key']),
30
- 'title': os.environ['title'],
31
- 'description': os.environ['description'],
32
- 'source_data_desc': os.environ['source_data_desc'],
33
- 'streaming': isTrue(os.environ.get('streaming', False)),
34
- 'prompt_name': os.environ.get('prompt_name', None),
35
- 'examples': os.environ.get('examples', None)
36
- })
37
- st.session_state.cfg = cfg
38
- st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_ids, cfg.prompt_name)
39
-
40
- cfg = st.session_state.cfg
41
- vq = st.session_state.vq
42
- st.set_page_config(page_title=cfg.title, layout="wide")
43
-
44
- # left side content
45
- with st.sidebar:
46
- image = Image.open('Vectara-logo.png')
47
- st.markdown(f"## Welcome to {cfg.title}\n\n"
48
- f"This demo uses Retrieval Augmented Generation to ask questions about {cfg.source_data_desc}\n\n")
49
 
50
- st.markdown("---")
51
- st.markdown(
52
- "## How this works?\n"
53
- "This app was built with [Vectara](https://vectara.com).\n"
54
- "Vectara's [Indexing API](https://docs.vectara.com/docs/api-reference/indexing-apis/indexing) was used to ingest the data into a Vectara corpus (or index).\n\n"
55
- "This app uses Vectara [Chat API](https://docs.vectara.com/docs/console-ui/vectara-chat-overview) to query the corpus and present the results to you, answering your question.\n\n"
56
- )
57
- st.markdown("---")
58
- st.image(image, width=250)
59
-
60
- st.markdown(f"<center> <h2> Vectara chat demo: {cfg.title} </h2> </center>", unsafe_allow_html=True)
61
- st.markdown(f"<center> <h4> {cfg.description} </h4> </center>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
-
64
-
65
  if "messages" not in st.session_state.keys():
66
  st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
67
 
 
11
  return x
12
  return x.strip().lower() == 'true'
13
 
14
+ def launch_bot():
15
+ def generate_response(question):
16
+ response = vq.submit_query(question)
17
+ return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ def generate_streaming_response(question):
20
+ response = vq.submit_query_streaming(question)
21
+ return response
22
+
23
+ if 'cfg' not in st.session_state:
24
+ corpus_ids = str(os.environ['corpus_ids']).split(',')
25
+ cfg = OmegaConf.create({
26
+ 'customer_id': str(os.environ['customer_id']),
27
+ 'corpus_ids': corpus_ids,
28
+ 'api_key': str(os.environ['api_key']),
29
+ 'title': os.environ['title'],
30
+ 'description': os.environ['description'],
31
+ 'source_data_desc': os.environ['source_data_desc'],
32
+ 'streaming': isTrue(os.environ.get('streaming', False)),
33
+ 'prompt_name': os.environ.get('prompt_name', None),
34
+ 'examples': os.environ.get('examples', None)
35
+ })
36
+ st.session_state.cfg = cfg
37
+ st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_ids, cfg.prompt_name)
38
+
39
+ cfg = st.session_state.cfg
40
+ vq = st.session_state.vq
41
+ st.set_page_config(page_title=cfg.title, layout="wide")
42
+
43
+ # left side content
44
+ with st.sidebar:
45
+ image = Image.open('Vectara-logo.png')
46
+ st.markdown(f"## Welcome to {cfg.title}\n\n"
47
+ f"This demo uses Retrieval Augmented Generation to ask questions about {cfg.source_data_desc}\n\n")
48
+
49
+ st.markdown("---")
50
+ st.markdown(
51
+ "## How this works?\n"
52
+ "This app was built with [Vectara](https://vectara.com).\n"
53
+ "Vectara's [Indexing API](https://docs.vectara.com/docs/api-reference/indexing-apis/indexing) was used to ingest the data into a Vectara corpus (or index).\n\n"
54
+ "This app uses Vectara [Chat API](https://docs.vectara.com/docs/console-ui/vectara-chat-overview) to query the corpus and present the results to you, answering your question.\n\n"
55
+ )
56
+ st.markdown("---")
57
+ st.image(image, width=250)
58
+
59
+ st.markdown(f"<center> <h2> Vectara chat demo: {cfg.title} </h2> </center>", unsafe_allow_html=True)
60
+ st.markdown(f"<center> <h4> {cfg.description} </h4> </center>", unsafe_allow_html=True)
61
+
62
 
63
+ with streamlit_analytics.track():
 
64
  if "messages" not in st.session_state.keys():
65
  st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
66