Spaces:
Sleeping
Sleeping
import streamlit as st | |
from tempfile import NamedTemporaryFile | |
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://shorturl.at/csCK3)", | |
"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] | |
title = st.text_input('Enter your own URL', 'https://shorturl.at/csCK3', disabled=not isCustomURL) | |
st.write('The current movie title is', title) | |
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) | |
if uploaded_file is not None: | |
with NamedTemporaryFile(dir='.', suffix=f'.{pdfCSVURLText.lower()}') as f: | |
f.write(uploaded_file.getbuffer()) | |
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) | |
if genre==radioButtonList[0]: | |
enableChatBox = True | |
elif genre==radioButtonList[1]: | |
enableChatBox = True | |
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 isCustomURL) | |
chatWithPDFButton = "CLICK HERE TO START CHATTING" | |
if st.button(chatWithPDFButton, type="primary"): | |
pass | |
else: | |
pass | |