-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
63 lines (47 loc) · 2.02 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
59
60
61
62
63
import streamlit as st
import pandas as pd
from pandasai import SmartDataframe
from langchain_groq import ChatGroq
from dotenv import load_dotenv
import os
# Loading environment variables from .env file
load_dotenv()
# Function to chat with CSV data
def chat_with_csv(df,query):
# Loading environment variables from .env file
load_dotenv()
# Function to initialize conversation chain with GROQ language model
groq_api_key = os.environ['GROQ_API_KEY']
# Initializing GROQ chat with provided API key, model name, and settings
llm = ChatGroq(
groq_api_key=groq_api_key, model_name="llama3-70b-8192",
temperature=0.2)
# Initialize SmartDataframe with DataFrame and LLM configuration
pandas_ai = SmartDataframe(df, config={"llm": llm})
# Chat with the DataFrame using the provided query
result = pandas_ai.chat(query)
return result
# Set layout configuration for the Streamlit page
st.set_page_config(layout='wide')
# Set title for the Streamlit application
st.title("Multiple-CSV ChatApp powered by LLM")
# Upload multiple CSV files
input_csvs = st.sidebar.file_uploader("Upload your CSV files", type=['csv'], accept_multiple_files=True)
# Check if CSV files are uploaded
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.head(3),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)
st.success(result)