Nolist commited on
Commit
2cdb239
·
verified ·
1 Parent(s): 33c552a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -52
app.py CHANGED
@@ -240,60 +240,11 @@ def save_victim_info(victim: dict):
240
  # -----------------------
241
  # OpenAI integration
242
  # -----------------------
243
- DEFAULT_MODEL = os.environ.get("OPENAI_MODEL", "gpt-4o-mini")
244
-
245
- # Initialize session state for temporary UI key
246
- if "ui_api_key" not in st.session_state:
247
- st.session_state.ui_api_key = "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"
248
 
249
  def get_openai_config_simple():
250
- """
251
- Returns a small config dict:
252
- {
253
- "OPENAI_apiKey": <string or None>,
254
- "OPENAI_model": <string or None>
255
- }
256
- Priority: env var -> st.secrets['openai'] -> session UI key
257
- """
258
- cfg = {
259
- "OPENAI_apiKey": os.environ.get("OPENAI_API_KEY"),
260
- "OPENAI_model": os.environ.get("OPENAI_MODEL"),
261
- }
262
-
263
- # Try reading .streamlit/secrets.toml [openai] table if present
264
- try:
265
- if hasattr(st, "secrets"):
266
- openai_sec = st.secrets.get("openai")
267
- if isinstance(openai_sec, dict):
268
- cfg["OPENAI_apiKey"] = openai_sec.get("OPENAI_API_KEY") or openai_sec.get("api_key") or cfg["OPENAI_apiKey"]
269
- cfg["OPENAI_model"] = openai_sec.get("OPENAI_MODEL") or openai_sec.get("model") or cfg["OPENAI_model"]
270
- except Exception:
271
- pass
272
-
273
- # fallback to the temporary UI key if nothing else
274
- if not cfg["OPENAI_apiKey"]:
275
- cfg["OPENAI_apiKey"] = st.session_state.get("ui_api_key")
276
-
277
- return cfg
278
-
279
- def get_effective_model():
280
- # Prefer env var
281
- env_model = os.environ.get("OPENAI_MODEL")
282
- if env_model:
283
- return env_model
284
-
285
- # Try Streamlit secrets (handle nested or flat)
286
- secret_model = None
287
- if hasattr(st, "secrets"):
288
- try:
289
- # Nested under [openai]
290
- secret_model = st.secrets["openai"]["OPENAI_MODEL"]
291
- except KeyError:
292
- # Flat key
293
- secret_model = st.secrets.get("OPENAI_MODEL")
294
-
295
- # Fallback to default
296
- return secret_model or DEFAULT_MODEL
297
 
298
  def make_openai_client(api_key):
299
  if not api_key:
 
240
  # -----------------------
241
  # OpenAI integration
242
  # -----------------------
243
+ OPENAI_api_key = st.secrets["OPENAI_API_KEY"]
244
+ OPENAI_model = st.secrets["OPENAI_MODEL"]
 
 
 
245
 
246
  def get_openai_config_simple():
247
+ return {"OPENAI_apiKey": OPENAI_api_key, "OPENAI_model": OPENAI_model}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  def make_openai_client(api_key):
250
  if not api_key: