Spaces:
Sleeping
Sleeping
# https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps | |
import os | |
import openai | |
import requests | |
import streamlit as st | |
from utils.util import * | |
from langchain.memory import ConversationBufferMemory | |
SAVE_DIR = "uploaded_files" | |
os.makedirs(SAVE_DIR, exist_ok=True) | |
def init_session_state(): | |
if "openai_api_key" not in st.session_state: | |
st.session_state.openai_api_key = "" | |
if "uploaded_files" not in st.session_state: | |
st.session_state.uploaded_files = os.listdir(SAVE_DIR) | |
init_session_state() | |
st.set_page_config(page_title="RegBotBeta", page_icon="📜🤖") | |
st.title("Welcome to RegBotBeta2.0") | |
st.header("Powered by `LlamaIndex🦙`, `Langchain🦜🔗 ` and `OpenAI API`") | |
# openai_api_key = st.text_input( | |
# "OpenAI API Key", | |
# type="password", | |
# help="Get your API key from https://platform.openai.com/account/api-keys", | |
# value=st.session_state.openai_api_key, | |
# ) | |
# isKeyValid = False | |
# if openai_api_key: | |
# resp = validate(openai_api_key) | |
# if "error" in resp.json(): | |
# st.info("Invalid Token! Try again.") | |
# else: | |
# st.info("Success") | |
# st.session_state.openai_api_key = openai_api_key | |
# isKeyValid = True | |
uploaded_files = st.file_uploader( | |
"Upload Files", | |
accept_multiple_files=True, | |
type=["pdf", "docx", "txt", "csv"], | |
) | |
if uploaded_files: | |
for file in uploaded_files: | |
if file not in st.session_state.uploaded_files: | |
# add the file to session state | |
st.session_state.uploaded_files.append(file.name) | |
# save the file to the sample_data directory | |
with open(os.path.join(SAVE_DIR, file.name), "wb") as f: | |
f.write(file.getbuffer()) | |
st.success("File(s) uploaded successfully!") | |
if st.session_state.uploaded_files: | |
st.write("Uploaded Files:") | |
for i, filename in enumerate(st.session_state.uploaded_files, start=1): | |
st.write(f"{i}. {filename}") | |