joao-vectara commited on
Commit
48f8fc0
·
verified ·
1 Parent(s): 9bb881d

Update app.py

Browse files

Adding agentic

Files changed (1) hide show
  1. app.py +65 -48
app.py CHANGED
@@ -1,52 +1,69 @@
1
  import streamlit as st
2
  from upload import upload_file_to_vectara
3
- from query import process_queries
4
  import os
 
 
 
 
5
 
6
- # Ensure set_page_config is the first Streamlit command
7
- st.set_page_config(page_title="STC Bank Assistant", layout="centered")
8
-
9
- # Load external CSS for custom styling
10
- with open("style.css", "r") as f:
11
- st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
12
-
13
- # Main UI layout
14
- st.markdown(
15
- """
16
- <h1>Welcome to the STC Bank Assistant</h1>
17
-
18
- <div class="icon-container">
19
- <!-- This yellowish box is the icon background -->
20
- <div class="icon-box">💼</div>
21
- <p class="icon-text">How may I help you?</p>
22
- </div>
23
-
24
- <h4>Add additional files here</h4>
25
- """,
26
- unsafe_allow_html=True
27
- )
28
-
29
- # Fetch credentials from environment variables
30
- customer_id = os.getenv("VECTARA_CUSTOMER_ID", "")
31
- api_key = os.getenv("VECTARA_API_KEY", "")
32
- corpus_id = os.getenv("VECTARA_CORPUS_ID", "")
33
- corpus_key = os.getenv("VECTARA_CORPUS_KEY", "")
34
-
35
- # File uploader with drag-and-drop text + limit note
36
- uploaded_files = st.file_uploader(
37
- "Drag and drop file here\nLimit 200MB per file",
38
- type=["pdf", "docx", "xlsx"],
39
- accept_multiple_files=True
40
- )
41
-
42
- # If credentials exist and files are uploaded, handle them
43
- if uploaded_files and customer_id and api_key and corpus_id and corpus_key:
44
- for file in uploaded_files:
45
- response = upload_file_to_vectara(file, customer_id, api_key, corpus_key)
46
- st.write(f"Uploaded {file.name}: {response}")
47
-
48
- if st.button("Run Queries"):
49
- results = process_queries(customer_id, api_key, corpus_key)
50
- for question, answer in results.items():
51
- st.subheader(question)
52
- st.write(answer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from upload import upload_file_to_vectara
3
+ #from query import process_queries
4
  import os
5
+ from st_app import launch_bot
6
+ import nest_asyncio
7
+ import asyncio
8
+ import uuid
9
 
10
+
11
+
12
+ # Setup for HTTP API Calls to Amplitude Analytics
13
+ if 'device_id' not in st.session_state:
14
+ st.session_state.device_id = str(uuid.uuid4())
15
+
16
+ if "feedback_key" not in st.session_state:
17
+ st.session_state.feedback_key = 0
18
+
19
+ if __name__ == "__main__":
20
+ # Ensure set_page_config is the first Streamlit command
21
+ st.set_page_config(page_title="STC Bank Assistant", layout="centered")
22
+
23
+ # Load external CSS for custom styling
24
+ with open("style.css", "r") as f:
25
+ st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
26
+
27
+ # Main UI layout
28
+ st.markdown(
29
+ """
30
+ <h1>Welcome to the STC Bank Assistant</h1>
31
+
32
+ <div class="icon-container">
33
+ <!-- This yellowish box is the icon background -->
34
+ <div class="icon-box">💼</div>
35
+ <p class="icon-text">How may I help you?</p>
36
+ </div>
37
+
38
+ <h4>Add additional files here</h4>
39
+ """,
40
+ unsafe_allow_html=True
41
+ )
42
+
43
+ # Fetch credentials from environment variables
44
+ customer_id = os.getenv("VECTARA_CUSTOMER_ID", "")
45
+ api_key = os.getenv("VECTARA_API_KEY", "")
46
+ corpus_id = os.getenv("VECTARA_CORPUS_ID", "")
47
+ corpus_key = os.getenv("VECTARA_CORPUS_KEY", "")
48
+
49
+ # File uploader with drag-and-drop text + limit note
50
+ uploaded_files = st.file_uploader(
51
+ "Drag and drop file here\nLimit 200MB per file",
52
+ type=["pdf", "docx", "xlsx"],
53
+ accept_multiple_files=True
54
+ )
55
+
56
+ # If credentials exist and files are uploaded, handle them
57
+ if uploaded_files and customer_id and api_key and corpus_id and corpus_key:
58
+ for file in uploaded_files:
59
+ response = upload_file_to_vectara(file, customer_id, api_key, corpus_key)
60
+ st.write(f"Uploaded {file.name}: {response}")
61
+
62
+ #if st.button("Run Queries"):
63
+ # results = process_queries(customer_id, api_key, corpus_key)
64
+ # for question, answer in results.items():
65
+ # st.subheader(question)
66
+ # st.write(answer)
67
+
68
+ nest_asyncio.apply()
69
+ asyncio.run(launch_bot())