File size: 3,154 Bytes
7ac0c16 dc1b795 7ac0c16 0ad91a6 4afa642 7ac0c16 6e45b74 7ac0c16 740d896 f3111ef 35607e9 f3111ef 0d2571c f3111ef 35607e9 f3111ef 740d896 7ac0c16 740d896 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
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
# Set the page configuration here
st.set_page_config(page_title="Insightly")
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.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(api_key=api_key, temperature=0, max_tokens=500) # Adjust max_tokens as needed
user_input = st.text_input("Question here:")
# Iterate over each CSV file
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)
# Perform any necessary data preprocessing or feature engineering here
# You can modify the code based on your specific requirements
# Example: Accessing columns from the DataFrame
# column_data = df["column_name"]
# Example: Applying transformations or calculations to the data
# transformed_data = column_data.apply(lambda x: x * 2)
# Example: Using the preprocessed data with the OpenAI API
# llm_response = llm.predict(transformed_data)
if user_input:
# Pass the user input to the OpenAI agent for processing
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)
# Add links to the sidebar with the same spacing properties
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-frame-capturer.hf.space/'> Frame Capturer</a></p>", unsafe_allow_html=True)
# Custom CSS to style the link and create vertical space
st.markdown(
"""
<style>
.image-container {
margin-bottom: 60px;
}
.sidebar-link {
display: flex;
justify-content: left;
font-size: 28px;
margin-top: 20px;
margin-left: 10px;
}
.vertical-space {
height: 20px;
}
</style>
""",
unsafe_allow_html=True,
)
if __name__ == "__main__":
main()
|