rairo commited on
Commit
96ede08
·
verified ·
1 Parent(s): 8cb8b3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pandasai.llm.openai import OpenAI
3
+ import pandas as pd
4
+ from pandasai import SmartDataframe, Agent
5
+ import io
6
+ import os
7
+
8
+ st.title("Brave Retail Insights")
9
+
10
+ openai_api_key = os.environ['openai_api_key']
11
+
12
+
13
+ llm = OpenAI(api_token=openai_api_key)
14
+
15
+ #uploader_file = st.file_uploader("Upload a CSV file", type=["csv"])
16
+
17
+
18
+ data = pd.read_csv("")
19
+ st.write(data.head(3))
20
+
21
+ df = SmartDataframe(data, config={"llm": llm})
22
+ agent = Agent(data, config={"llm": llm, "open_charts": "False"})
23
+
24
+ prompt = st.text_area("Enter your prompt:")
25
+ system_prompt = "Decide whether this needs a graph. If it does determine what type of graph (i.e. line/scatter/bar/pie etc). then generate the graph according to the requirements. we may not always need you to generate a graph. if a graph is not required just generate a written output. If you are generating a graph also include a brief description."
26
+ full_prompt = "Main query: " + prompt + " Instructions: " + system_prompt
27
+
28
+ if st.button("Generate"):
29
+ if prompt:
30
+ with st.spinner("Generating response..."):
31
+ try:
32
+ graph = df.chat(full_prompt)
33
+ if "temp_chart" in str(graph):
34
+ st.image(graph)
35
+
36
+ response = agent.chat(prompt + " Instructions: we don't generate graphs even if it is asked for")
37
+ if "temp_chart" not in str(response):
38
+ st.write(response)
39
+
40
+ with st.expander("See Explanation:"):
41
+ st.write(agent.explain())
42
+ except Exception as e:
43
+ st.error(f"An error occurred: {e}")
44
+ else:
45
+ st.warning("Please enter a prompt!")