-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchatbot_app.py
More file actions
69 lines (46 loc) · 1.86 KB
/
chatbot_app.py
File metadata and controls
69 lines (46 loc) · 1.86 KB
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
import pandas as pd
import streamlit as st
from pandasai import SmartDataframe
from pandasai.responses.response_parser import ResponseParser
from pandasai.llm import OpenAI
class StreamlitResponse(ResponseParser):
def __init__(self, context)-> None :
super().__init__(context)
def format_dataframe(self, result):
st.dataframe(result["value"])
return
def format_plot(self, result):
st.image(result["value"])
return
def format_other(self, result):
st.write(result["value"])
return
# make the app wider
st.set_page_config(layout='wide')
# set the title
st.title (" ChatBot : Prompt Based Data Analysis and Visualization ")
st.markdown('---') # to make line
# file uploader using streamlit
upload_csv_file = st.file_uploader("Upload Your CSV file for data analysis and visualization", type = ["csv"])
# if statement to make sure the data is uploaded
if upload_csv_file is not None:
data = pd.read_csv(upload_csv_file)
data.columns = data.columns.str.upper() #convert the columns to uppercase
st.table(data.head(5))
st.write(' Data Uploaded Successfully!')
st.markdown('---')
st.write ( '### Enter Your Analysis or Visualization Request')
query = st.text_area(" Enter your prompt")
llm = OpenAI(api_token= 'open_ai_secret_api_key') # api key starts with something sk-...
if st.button ("Submit"):
if query:
with st.spinner("Loading wait.."):
st.write ( '### OUTPUT : ')
st.markdown('---')
query_engine = SmartDataframe(data, config = {'llm':llm, "response_parser": StreamlitResponse})
# query_engine = SmartDataframe(data, config = {'llm':llm})
# answer = query_engine.chat(query)
query_engine.chat(query)
# st.write(answer)
else:
st.warning("Please enter a prompt")