-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (50 loc) · 2 KB
/
app.py
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
#Importing all the libraries
import streamlit as st
from pandasai.llm.openai import OpenAI
from dotenv import load_dotenv
import os
import pandas as pd
#from pandasai import PandasAI
from pandasai import SmartDataframe
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
load_dotenv()
#OpenAI api key
openai_api_key = os.getenv("OPENAI_API_KEY")
#Function to build LLM and Chat With Multiple CSV FIles
def chat_with_csv(df,prompt):
llm = OpenAI(api_token=openai_api_key)
pandas_ai = SmartDataframe(df, config={"llm": llm})
#pandas_ai = PandasAI(llm, save_charts=True)
result = pandas_ai.chat(prompt)
#result = pandas_ai.run(df,prompt=prompt)
return result
st.set_page_config(layout='wide')
st.title("IntelliExtract-AI")
st.markdown('<style>h1{color: #6A0DAD; text-align: center;}</style>', unsafe_allow_html=True)
st.subheader('Harnessing LLM for Intelligent Information Extraction.')
st.markdown('<style>h3{color: #003366; text-align: center;}</style>', unsafe_allow_html=True)
# Upload multiple CSV files
input_csvs = st.sidebar.file_uploader("Upload your CSV files", type=['csv'], accept_multiple_files=True)
if input_csvs:
# Select a CSV file from the uploaded files using a dropdown menu
selected_file = st.selectbox("Select a CSV file", [file.name for file in input_csvs])
selected_index = [file.name for file in input_csvs].index(selected_file)
#load and display the selected csv file
st.info("CSV uploaded successfully")
data = pd.read_csv(input_csvs[selected_index])
st.dataframe(data,use_container_width=True)
#Enter the query for analysis
st.info("Chat Below")
input_text = st.text_area("Enter the query")
#Perform analysis
if input_text:
if st.button("Chat with csv"):
st.info("Your Query: "+ input_text)
result = chat_with_csv(data,input_text)
fig_number = plt.get_fignums()
if fig_number:
st.pyplot(plt.gcf())
else:
st.success(result)