ProaC / app.py
joao-vectara's picture
Update app.py
9bb881d verified
raw
history blame
1.71 kB
import streamlit as st
from upload import upload_file_to_vectara
from query import process_queries
import os
# Ensure set_page_config is the first Streamlit command
st.set_page_config(page_title="STC Bank Assistant", layout="centered")
# Load external CSS for custom styling
with open("style.css", "r") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
# Main UI layout
st.markdown(
"""
<h1>Welcome to the STC Bank Assistant</h1>
<div class="icon-container">
<!-- This yellowish box is the icon background -->
<div class="icon-box">💼</div>
<p class="icon-text">How may I help you?</p>
</div>
<h4>Add additional files here</h4>
""",
unsafe_allow_html=True
)
# Fetch credentials from environment variables
customer_id = os.getenv("VECTARA_CUSTOMER_ID", "")
api_key = os.getenv("VECTARA_API_KEY", "")
corpus_id = os.getenv("VECTARA_CORPUS_ID", "")
corpus_key = os.getenv("VECTARA_CORPUS_KEY", "")
# File uploader with drag-and-drop text + limit note
uploaded_files = st.file_uploader(
"Drag and drop file here\nLimit 200MB per file",
type=["pdf", "docx", "xlsx"],
accept_multiple_files=True
)
# If credentials exist and files are uploaded, handle them
if uploaded_files and customer_id and api_key and corpus_id and corpus_key:
for file in uploaded_files:
response = upload_file_to_vectara(file, customer_id, api_key, corpus_key)
st.write(f"Uploaded {file.name}: {response}")
if st.button("Run Queries"):
results = process_queries(customer_id, api_key, corpus_key)
for question, answer in results.items():
st.subheader(question)
st.write(answer)