Manojkumarpandi commited on
Commit
b9e1489
·
verified ·
1 Parent(s): 1bba314

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -30
app.py CHANGED
@@ -2,25 +2,21 @@ import streamlit as st
2
  import os
3
  import json
4
  import requests
5
- from google import genai
6
- from google.genai import types
7
- from dotenv import load_dotenv
8
 
9
- load_dotenv()
 
 
10
 
11
- # Set page configuration
12
- st.set_page_config(
13
- page_title="Flaix - Financial Assistant",
14
- page_icon="💰",
15
- layout="centered"
16
- )
17
 
18
  # Initialize Gemini client
19
- api_key = st.secrets["GOOGLE_API_KEY"]
20
- client = genai.Client(api_key=api_key)
21
 
22
  # Indian Stock Market API base configuration
23
- INDIAN_API_KEY = st.secrets["FINANCE_KEY"]
24
  INDIAN_API_BASE_URL = "https://stock.indianapi.in"
25
 
26
  # Define API endpoints and their parameters
@@ -177,28 +173,16 @@ def orchestrator(query):
177
 
178
  # Create content for the orchestrator
179
  contents = [
180
- types.Content(
181
- role="user",
182
- parts=[
183
- types.Part.from_text(text=orchestrator_prompt)
184
- ],
185
- ),
186
  ]
187
 
188
- # Configure generation parameters
189
- generate_content_config = types.GenerateContentConfig(
190
- temperature=0.2,
191
- top_p=0.95,
192
- top_k=40,
193
- max_output_tokens=500,
194
- response_mime_type="text/plain",
195
- )
196
-
197
  # Generate content
198
- response = client.models.generate_content(
199
  model="gemini-1.5-flash",
200
  contents=contents,
201
- config=generate_content_config,
202
  )
203
 
204
  # Parse the response
@@ -218,6 +202,7 @@ def orchestrator(query):
218
  print(f"Error parsing orchestrator response: {e}")
219
  return {"needs_api": False}
220
 
 
221
  # Language setting
222
 
223
  # Financial assistant system prompt
 
2
  import os
3
  import json
4
  import requests
5
+ import google.generativeai as genai
 
 
6
 
7
+ # Load environment variables
8
+ api_key = os.getenv("GOOGLE_API_KEY")
9
+ finance_key = os.getenv("FINANCE_KEY")
10
 
11
+ if not api_key or not finance_key:
12
+ st.error("API keys not found. Please check your configuration.")
13
+ st.stop()
 
 
 
14
 
15
  # Initialize Gemini client
16
+ genai.configure(api_key=api_key)
 
17
 
18
  # Indian Stock Market API base configuration
19
+ INDIAN_API_KEY = finance_key
20
  INDIAN_API_BASE_URL = "https://stock.indianapi.in"
21
 
22
  # Define API endpoints and their parameters
 
173
 
174
  # Create content for the orchestrator
175
  contents = [
176
+ {
177
+ "role": "user",
178
+ "parts": [orchestrator_prompt]
179
+ }
 
 
180
  ]
181
 
 
 
 
 
 
 
 
 
 
182
  # Generate content
183
+ response = genai.generate_content(
184
  model="gemini-1.5-flash",
185
  contents=contents,
 
186
  )
187
 
188
  # Parse the response
 
202
  print(f"Error parsing orchestrator response: {e}")
203
  return {"needs_api": False}
204
 
205
+
206
  # Language setting
207
 
208
  # Financial assistant system prompt