test12 / app.py
shreyasiv's picture
app file
aff2ccc
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()