rairo commited on
Commit
a8bb1e2
·
verified ·
1 Parent(s): 53cc0dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -5
app.py CHANGED
@@ -10,6 +10,9 @@ import io
10
  import base64
11
  import requests
12
 
 
 
 
13
  # API Endpoint and payload
14
  API_URL = "https://irisplus.elixir.co.zw/public/api/profile/reporting/stock-card/genericReports"
15
  PAYLOAD = {
@@ -37,6 +40,21 @@ def fetch_data():
37
  st.error(f"Error fetching data: {response.status_code} - {response.text}")
38
  return None
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  class StreamLitResponse(ResponseParser):
41
  def __init__(self, context):
42
  super().__init__(context)
@@ -83,6 +101,21 @@ if not GOOGLE_API_KEY:
83
  st.error("GOOGLE_API_KEY environment variable not set.")
84
  st.stop()
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  def generateResponse(prompt, df):
87
  """Generate response using PandasAI with SmartDataframe"""
88
  llm = GoogleGemini(api_key=GOOGLE_API_KEY)
@@ -206,13 +239,13 @@ def main():
206
  with st.expander("Preview"):
207
  st.dataframe(filtered_df.head())
208
  with st.spinner("Generating Report, Please Wait...."):
209
- prompt = (
210
  "You are an expert business analyst. Analyze the following data and generate a comprehensive and insightful business report "
211
- "including key performance indicators and recommendations.\n\nData:\n" + str(filtered_df.to_json(orient='records'))
212
- )
213
- response = generateResponse(prompt, filtered_df)
214
  # Display the report text; adjust according to your response format.
215
- st.markdown(response.get("value", "No report generated."))
216
  else:
217
  st.error("No data available for reports.")
218
 
 
10
  import base64
11
  import requests
12
 
13
+
14
+
15
+
16
  # API Endpoint and payload
17
  API_URL = "https://irisplus.elixir.co.zw/public/api/profile/reporting/stock-card/genericReports"
18
  PAYLOAD = {
 
40
  st.error(f"Error fetching data: {response.status_code} - {response.text}")
41
  return None
42
 
43
+ gemini_api_key = os.environ['GOOGLE_API_KEY']
44
+
45
+ genai.configure(api_key=gemini_api_key)
46
+
47
+ generation_config = {
48
+ "temperature": 0.2,
49
+ "top_p": 0.95,
50
+ "max_output_tokens": 5000,
51
+ }
52
+
53
+ model = genai.GenerativeModel(
54
+ model_name="gemini-2.0-flash-thinking-exp",
55
+ generation_config=generation_config,
56
+ )
57
+
58
  class StreamLitResponse(ResponseParser):
59
  def __init__(self, context):
60
  super().__init__(context)
 
101
  st.error("GOOGLE_API_KEY environment variable not set.")
102
  st.stop()
103
 
104
+ gemini_api_key = os.environ['GOOGLE_API_KEY']
105
+
106
+ genai.configure(api_key=gemini_api_key)
107
+
108
+ generation_config = {
109
+ "temperature": 0.2,
110
+ "top_p": 0.95,
111
+ "max_output_tokens": 5000,
112
+ }
113
+
114
+ model = genai.GenerativeModel(
115
+ model_name="gemini-2.0-flash-thinking-exp",
116
+ generation_config=generation_config,
117
+ )
118
+
119
  def generateResponse(prompt, df):
120
  """Generate response using PandasAI with SmartDataframe"""
121
  llm = GoogleGemini(api_key=GOOGLE_API_KEY)
 
239
  with st.expander("Preview"):
240
  st.dataframe(filtered_df.head())
241
  with st.spinner("Generating Report, Please Wait...."):
242
+ prompt = f"""
243
  "You are an expert business analyst. Analyze the following data and generate a comprehensive and insightful business report "
244
+ "including key performance indicators and recommendations.\n\nData:\n" + {str(filtered_df.to_json(orient='records'))}
245
+ """
246
+ response = model.generate_content(prompt)
247
  # Display the report text; adjust according to your response format.
248
+ st.markdown(response.txt)
249
  else:
250
  st.error("No data available for reports.")
251