Spaces:
Sleeping
Sleeping
import streamlit as st | |
from tempfile import NamedTemporaryFile | |
import pprint | |
import google.generativeai as palm | |
import os | |
from dotenv import load_dotenv, find_dotenv | |
from langchain.embeddings import GooglePalmEmbeddings | |
from langchain.llms import GooglePalm | |
from langchain.document_loaders import UnstructuredURLLoader #load urls into docoument-loader | |
from langchain.chains.question_answering import load_qa_chain | |
from langchain.indexes import VectorstoreIndexCreator #vectorize db index with chromadb | |
from langchain.text_splitter import CharacterTextSplitter #text splitter | |
from langchain.chains import RetrievalQA | |
from langchain.document_loaders import UnstructuredPDFLoader #load pdf | |
from langchain.agents import create_pandas_dataframe_agent | |
import pandas as pd | |
import numpy as np | |
import pprint | |
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) | |
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 | |
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 = True | |
chatTextStr = 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 and not chatTextStr): # Button Cliked | |
st.write('Invalid ULR. Please enter a valid URL.') | |
# else: | |
# pass | |