File size: 2,689 Bytes
7d849d3
413cb20
e4b3526
7d849d3
9830b8e
 
 
e4b3526
4b4013f
b16e227
9830b8e
 
b16e227
874fc5b
63e083c
874fc5b
 
 
 
 
 
 
 
 
 
 
 
6a1c9b8
63e083c
e4b3526
 
4b4013f
413cb20
6cbfbad
e4b3526
4b4013f
6cbfbad
413cb20
e4b3526
 
4b4013f
 
413cb20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b4013f
005a493
413cb20
 
 
e4b3526
 
 
 
413cb20
e4b3526
 
874fc5b
e4b3526
874fc5b
005a493
874fc5b
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import streamlit as st
from tempfile import NamedTemporaryFile
import validators

radioButtonList = ["E-commerce CSV (https://www.kaggle.com/datasets/mervemenekse/ecommerce-dataset)",
"Upload my own CSV",
"Upload my own PDF",
"URL Chat with Google Alphabet's 2022 Q2 Earnings Report (https://tinyurl.com/f85wujsj)",
"Enter my own URL"]
genre = st.radio(
    "Choose dataset to finetune", radioButtonList
    )

pdfCSVURLText = ""
if genre==radioButtonList[0]:
    pdfCSVURLText = "CSV"
    # st.write('You selected comedy.')
    # else:
    # st.write(f'''Password streamlit app: {st.secrets["PSWD"]}''')
elif genre==radioButtonList[1]:
    pdfCSVURLText = "CSV"
elif genre==radioButtonList[2]:
    pdfCSVURLText = "PDF"
elif genre==radioButtonList[3]:
    pdfCSVURLText = "URL"
elif genre==radioButtonList[4]:
    pdfCSVURLText = "URL"

isCustomURL = genre==radioButtonList[4]
urlInput = st.text_input('Enter your own URL', '', placeholder="Type your URL here (e.g. https://tinyurl.com/f85wujsj)", disabled=not isCustomURL)
isValidURL = validators.url(urlInput)

isCustomPDF = genre==radioButtonList[1] or genre==radioButtonList[2]
uploaded_file = st.file_uploader(f"Upload your own {pdfCSVURLText} here", type=pdfCSVURLText.lower(), disabled=not isCustomPDF)
uploadedFilename = ""
if uploaded_file is not None:
    with NamedTemporaryFile(dir='.', suffix=f'.{pdfCSVURLText.lower()}') as f:
        f.write(uploaded_file.getbuffer())
        uploadedFilename = f.name
        # st.write('The current uploaded file is', f.name)


    # # To read file as bytes:
    # bytes_data = uploaded_file.getvalue()
    # st.write(bytes_data)
    #
    # # To convert to a string based IO:
    # stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
    # st.write(stringio)
    #
    # # To read file as string:
    # string_data = stringio.read()
    # st.write(string_data)
    #
    # # Can be used wherever a "file-like" object is accepted:
    # dataframe = pd.read_csv(uploaded_file)
    # st.write(dataframe)

enableChatBox = False
if genre==radioButtonList[0]:
    enableChatBox = True
elif genre==radioButtonList[1]:
    enableChatBox = uploadedFilename[-4:]==".csv"
elif genre==radioButtonList[2]:
    enableChatBox = uploadedFilename[-4:]==".pdf"
elif genre==radioButtonList[3]:
    enableChatBox = True
elif genre==radioButtonList[4]:
    enableChatBox = isValidURL

title = st.text_input(f'Ask me anything about this {pdfCSVURLText}', '', placeholder="Type your question here (e.g. what was the most sold item?)", disabled=not enableChatBox)
chatWithPDFButton = "CLICK HERE TO START CHATTING"
if st.button(chatWithPDFButton, disabled=not enableChatBox):
    pass
else:
    pass