|
from tempfile import NamedTemporaryFile |
|
from langchain.agents import create_csv_agent |
|
from langchain.llms import OpenAI |
|
from dotenv import load_dotenv |
|
import os |
|
import streamlit as st |
|
import pandas as pd |
|
from streamlit_chat import message |
|
from langchain.embeddings.openai import OpenAIEmbeddings |
|
from langchain.chat_models import ChatOpenAI |
|
from langchain.chains import ConversationalRetrievalChain |
|
from langchain.document_loaders.csv_loader import CSVLoader |
|
from langchain.vectorstores import FAISS |
|
|
|
def main(): |
|
load_dotenv() |
|
|
|
|
|
api_key = os.getenv("OPENAI_API_KEY") |
|
if api_key is None or api_key == "": |
|
st.error("OPENAI_API_KEY is not set") |
|
return |
|
|
|
st.set_page_config(page_title="Insightly") |
|
st.sidebar.image("https://i.ibb.co/bX6GdqG/insightly-wbg.png", use_column_width=True) |
|
st.title("Data Analysis π") |
|
|
|
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True) |
|
if csv_files: |
|
llm = OpenAI(temperature=0) |
|
user_input = st.text_input("Question here:") |
|
|
|
|
|
for csv_file in csv_files: |
|
with NamedTemporaryFile(delete=False) as f: |
|
f.write(csv_file.getvalue()) |
|
f.flush() |
|
df = pd.read_csv(f.name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if user_input: |
|
|
|
agent = create_csv_agent(llm, f.name, verbose=True) |
|
response = agent.run(user_input) |
|
|
|
st.write(f"CSV File: {csv_file.name}") |
|
st.write("Response:") |
|
st.write(response) |
|
|
|
|
|
|
|
st.sidebar.markdown("<p class='sidebar-link'>π <a href='https://chandrakalagowda-demo2.hf.space/'> PDF Bot </a></p>", unsafe_allow_html=True) |
|
st.sidebar.markdown("<p class='sidebar-link'>πΌοΈ <a href='https://insightly-image-reader.hf.space'> Image Reader</a></p>", unsafe_allow_html=True) |
|
st.sidebar.markdown("<p class='sidebar-link'>πΈ <a href='https://insightly-csv-bot.hf.space/'> Frame Capturer</a></p>", unsafe_allow_html=True) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|