Spaces:
Running
Running
Adding files
Browse files- app.py +58 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### importing required libraries
|
2 |
+
from pandasai.responses.streamlit_response import StreamlitResponse
|
3 |
+
from langchain_groq import ChatGroq
|
4 |
+
from pandasai import SmartDataframe
|
5 |
+
import streamlit as st
|
6 |
+
import pandas as pd
|
7 |
+
import shutil
|
8 |
+
import os
|
9 |
+
|
10 |
+
### using Mixtral 8 x 7b model with Groq's LPU Inference Engine
|
11 |
+
llm = ChatGroq(model_name = "mixtral-8x7b-32768", temperature = 0.1)
|
12 |
+
|
13 |
+
### building the streamlit interface
|
14 |
+
st.title("Smart Analyzer: Natural Language, Powerful Results")
|
15 |
+
dataFile = st.file_uploader(label = "Upload a csv/xlsx file for analysis", type = ["csv", "xlsx"])
|
16 |
+
|
17 |
+
if dataFile != None:
|
18 |
+
extension = dataFile.name.split(".")[-1]
|
19 |
+
if extension.lower() == "csv":
|
20 |
+
dataframe = pd.read_csv(dataFile)
|
21 |
+
elif extension.lower() == "xlsx":
|
22 |
+
dataframe = pd.read_excel(dataFile)
|
23 |
+
else:
|
24 |
+
st.warning("Invalid File Chosen")
|
25 |
+
|
26 |
+
st.write(dataframe.head(3))
|
27 |
+
|
28 |
+
smartDataFrame = SmartDataframe(dataframe, config = {
|
29 |
+
"llm": llm,
|
30 |
+
"custom_whitelisted_dependencies": ["IPython", "os", "matplotlib", "seaborn", "pandas"],
|
31 |
+
"response_parser": StreamlitResponse,
|
32 |
+
"verbose": True
|
33 |
+
}
|
34 |
+
)
|
35 |
+
|
36 |
+
prompt = st.text_area("Enter your query, question, or desired operation")
|
37 |
+
|
38 |
+
if st.button("Generate Answer"):
|
39 |
+
chartsDirectory = os.path.join("exports", "charts")
|
40 |
+
if os.path.isdir(chartsDirectory):
|
41 |
+
if len(os.listdir(chartsDirectory)) != 0:
|
42 |
+
shutil.rmtree(chartsDirectory)
|
43 |
+
else: pass
|
44 |
+
os.rmdir(chartsDirectory)
|
45 |
+
else: pass
|
46 |
+
|
47 |
+
if prompt:
|
48 |
+
with st.spinner("Analyzing data, generating a response..."):
|
49 |
+
response = smartDataFrame.chat(prompt)
|
50 |
+
if len(os.listdir(chartsDirectory)) != 0:
|
51 |
+
imgName = os.listdir(chartsDirectory)[0]
|
52 |
+
imgPath = os.path.join(chartsDirectory, imgName)
|
53 |
+
st.image(imgPath)
|
54 |
+
shutil.rmtree(chartsDirectory)
|
55 |
+
else:
|
56 |
+
st.write(response)
|
57 |
+
else:
|
58 |
+
st.warning("Please enter a prompt")
|
requirements.txt
ADDED
Binary file (2.72 kB). View file
|
|