Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,7 @@ from langchain.llms import OpenAI
|
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import os
|
| 6 |
import streamlit as st
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
def main():
|
| 11 |
load_dotenv()
|
|
@@ -20,18 +19,38 @@ def main():
|
|
| 20 |
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
| 21 |
st.header("Data Analysis π")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
if
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
main()
|
|
|
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import os
|
| 6 |
import streamlit as st
|
| 7 |
+
import pandas as pd
|
|
|
|
| 8 |
|
| 9 |
def main():
|
| 10 |
load_dotenv()
|
|
|
|
| 19 |
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
| 20 |
st.header("Data Analysis π")
|
| 21 |
|
| 22 |
+
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
|
| 23 |
+
if csv_files:
|
| 24 |
+
llm = OpenAI(temperature=0)
|
| 25 |
+
user_input = st.text_input("Question here:")
|
| 26 |
+
|
| 27 |
+
# Iterate over each CSV file
|
| 28 |
+
for csv_file in csv_files:
|
| 29 |
+
with NamedTemporaryFile(delete=False) as f:
|
| 30 |
+
f.write(csv_file.getvalue())
|
| 31 |
+
f.flush()
|
| 32 |
+
df = pd.read_csv(f.name)
|
| 33 |
+
|
| 34 |
+
# Perform any necessary data preprocessing or feature engineering here
|
| 35 |
+
# You can modify the code based on your specific requirements
|
| 36 |
+
|
| 37 |
+
# Example: Accessing columns from the DataFrame
|
| 38 |
+
# column_data = df["column_name"]
|
| 39 |
+
|
| 40 |
+
# Example: Applying transformations or calculations to the data
|
| 41 |
+
# transformed_data = column_data.apply(lambda x: x * 2)
|
| 42 |
+
|
| 43 |
+
# Example: Using the preprocessed data with the OpenAI API
|
| 44 |
+
# llm_response = llm.predict(transformed_data)
|
| 45 |
+
|
| 46 |
+
if user_input:
|
| 47 |
+
# Pass the user input to the OpenAI agent for processing
|
| 48 |
+
agent = create_csv_agent(llm, f.name, verbose=True)
|
| 49 |
+
response = agent.run(user_input)
|
| 50 |
|
| 51 |
+
st.write(f"CSV File: {csv_file.name}")
|
| 52 |
+
st.write("Response:")
|
| 53 |
+
st.write(response)
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|