File size: 1,100 Bytes
aff2ccc |
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 |
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
def main():
load_dotenv()
# Load the OpenAI API key from the environment variable
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("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
st.header("Data Analysis 📈")
csv_file = st.file_uploader("Upload a CSV file", type="csv")
if csv_file:
with NamedTemporaryFile(delete=False) as f:
f.write(csv_file.getvalue())
f.flush()
llm = OpenAI(temperature=0)
user_input = st.text_input("Question here:")
agent = create_csv_agent(llm, f.name, verbose=True)
if user_input:
response = agent.run(user_input)
st.write(response)
if __name__ == "__main__":
main() |