Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,25 +2,21 @@ import streamlit as st
|
|
2 |
import os
|
3 |
import json
|
4 |
import requests
|
5 |
-
|
6 |
-
from google.genai import types
|
7 |
-
from dotenv import load_dotenv
|
8 |
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
st.
|
13 |
-
|
14 |
-
page_icon="💰",
|
15 |
-
layout="centered"
|
16 |
-
)
|
17 |
|
18 |
# Initialize Gemini client
|
19 |
-
api_key
|
20 |
-
client = genai.Client(api_key=api_key)
|
21 |
|
22 |
# Indian Stock Market API base configuration
|
23 |
-
INDIAN_API_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 |
-
|
181 |
-
role
|
182 |
-
parts
|
183 |
-
|
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 =
|
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
|