Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,8 @@ import pandas as pd
|
|
| 5 |
from pandasai import SmartDataframe
|
| 6 |
from pandasai.responses.response_parser import ResponseParser
|
| 7 |
from st_on_hover_tabs import on_hover_tabs
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class StreamLitResponse(ResponseParser):
|
| 10 |
def __init__(self,context) -> None:
|
|
@@ -21,6 +23,19 @@ class StreamLitResponse(ResponseParser):
|
|
| 21 |
|
| 22 |
gemini_api_key = os.environ['Gemini']
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def calculate_kpis(df):
|
| 25 |
"""
|
| 26 |
Calculates key performance indicators from a given transaction dataset.
|
|
@@ -69,6 +84,12 @@ def calculate_kpis(df):
|
|
| 69 |
|
| 70 |
return json.dumps(kpis, indent=4)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def generateResponse(dataFrame,prompt):
|
| 73 |
llm = GoogleGemini(api_key=gemini_api_key)
|
| 74 |
pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
|
|
@@ -105,4 +126,13 @@ if tabs =='Chat':
|
|
| 105 |
st.write(answer)
|
| 106 |
|
| 107 |
elif tabs == 'Reports':
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from pandasai import SmartDataframe
|
| 6 |
from pandasai.responses.response_parser import ResponseParser
|
| 7 |
from st_on_hover_tabs import on_hover_tabs
|
| 8 |
+
from ydata_profiling import ProfileReport
|
| 9 |
+
import google.generativeai as genai
|
| 10 |
|
| 11 |
class StreamLitResponse(ResponseParser):
|
| 12 |
def __init__(self,context) -> None:
|
|
|
|
| 23 |
|
| 24 |
gemini_api_key = os.environ['Gemini']
|
| 25 |
|
| 26 |
+
genai.configure(api_key=gemini_api_key)
|
| 27 |
+
|
| 28 |
+
generation_config = {
|
| 29 |
+
"temperature": 0.2,
|
| 30 |
+
"top_p": 0.95,
|
| 31 |
+
"max_output_tokens": 5000,
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
model = genai.GenerativeModel(
|
| 35 |
+
model_name="gemini-1.5-flash",
|
| 36 |
+
generation_config=generation_config,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
def calculate_kpis(df):
|
| 40 |
"""
|
| 41 |
Calculates key performance indicators from a given transaction dataset.
|
|
|
|
| 84 |
|
| 85 |
return json.dumps(kpis, indent=4)
|
| 86 |
|
| 87 |
+
|
| 88 |
+
def get_pandas_profile(df):
|
| 89 |
+
profile = ProfileReport(df, title="Profiling Report")
|
| 90 |
+
json_profile = profile.to_json()
|
| 91 |
+
return json_profile
|
| 92 |
+
|
| 93 |
def generateResponse(dataFrame,prompt):
|
| 94 |
llm = GoogleGemini(api_key=gemini_api_key)
|
| 95 |
pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
|
|
|
|
| 126 |
st.write(answer)
|
| 127 |
|
| 128 |
elif tabs == 'Reports':
|
| 129 |
+
st.header("Reports")
|
| 130 |
+
prompt = """
|
| 131 |
+
You are an expert business analyst. Analyze the following data and generate a comprehensive and insightful business report, including appropriate key perfomance indicators and reccomendations.
|
| 132 |
+
|
| 133 |
+
data:
|
| 134 |
+
""" + str(calculate_kpis(df)) + str(get_pandas_profile(df))
|
| 135 |
+
|
| 136 |
+
response = model.generate_content(prompt)
|
| 137 |
+
report = response.text
|
| 138 |
+
st.write(report)
|