File size: 1,630 Bytes
23a229c
 
0809507
 
402c1d3
0809507
0e8a2bc
 
3b7cf58
0809507
4bb745d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19f4fce
23a229c
19f4fce
 
91caeb5
f5254ad
 
 
 
 
 
 
4bb745d
 
 
 
 
 
 
 
 
 
 
 
91caeb5
4bb745d
 
 
23a229c
4bb745d
23a229c
4bb745d
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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`")


def init_session_state():
    if "huggingface_token" not in st.session_state:
        st.session_state.huggingface_token = ""


init_session_state()

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}")