1na37 commited on
Commit
5fa5a9c
Β·
verified Β·
1 Parent(s): a9d312d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -48
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # ============================================================
2
- # 🏦 SME Credit Risk Assessment β€” Streamlit App v6 (FINAL)
3
  # Final Project | AI Engineering Bootcamp Batch 10
4
  # Author: 1na37
5
  # ============================================================
@@ -282,19 +282,19 @@ with st.sidebar:
282
  )
283
  st.markdown("---")
284
 
285
- with st.expander(T('sidebar_api', lang)):
286
- st.caption("πŸ’‘ Jika sudah set di HF Secrets, biarkan kosong." if lang=='id' else
287
- "πŸ’‘ If already set in HF Secrets, leave blank.")
288
- _or_manual = st.text_input("OpenRouter API Key", type="password",
289
- value="", placeholder="sk-or-... (opsional)",
290
- key="or_manual_input")
291
- _gem_manual = st.text_input("Gemini API Key", type="password",
292
- value="", placeholder="AIza... (opsional)",
293
- key="gem_manual_input")
294
- _groq_manual = st.text_input("Groq API Key", type="password",
295
- value="", placeholder="gsk_... (opsional)",
296
- key="groq_manual_input")
297
- st.caption(T('sidebar_api_note', lang))
298
 
299
  st.markdown("---")
300
  st.markdown(T('sidebar_stack', lang))
@@ -306,40 +306,6 @@ with st.sidebar:
306
  st.markdown(stack_items[lang])
307
  st.caption(T('sidebar_footer', lang))
308
 
309
- # ============================================================
310
- # AMBIL API KEY
311
- # ============================================================
312
- def _get_key(session_key: str, secret_name: str) -> str:
313
- manual = st.session_state.get(session_key, "")
314
- if isinstance(manual, str) and manual.strip():
315
- return manual.strip()
316
- return _read_secret(secret_name)
317
-
318
- openrouter_key = _get_key("or_manual_input", "OPENROUTER_API_KEY")
319
- gemini_key = _get_key("gem_manual_input", "GEMINI_API_KEY")
320
- groq_key = _get_key("groq_manual_input", "GROQ_API_KEY")
321
-
322
- def _key_source(session_key, secret_name):
323
- manual = st.session_state.get(session_key, "")
324
- if isinstance(manual, str) and manual.strip():
325
- return "βœ… manual"
326
- try:
327
- if st.secrets[secret_name]:
328
- return "βœ… secret"
329
- except Exception:
330
- pass
331
- if os.environ.get(secret_name, ""):
332
- return "βœ… env"
333
- return "❌"
334
-
335
- with st.sidebar:
336
- st.markdown("---")
337
- st.caption(
338
- f"πŸ”‘ OR: {_key_source('or_manual_input','OPENROUTER_API_KEY')} "
339
- f"Gem: {_key_source('gem_manual_input','GEMINI_API_KEY')} "
340
- f"Groq: {_key_source('groq_manual_input','GROQ_API_KEY')}"
341
- )
342
-
343
  # ============================================================
344
  # LOAD MODEL & RAG
345
  # ============================================================
 
1
  # ============================================================
2
+ # 🏦 SME Credit Risk Assessment
3
  # Final Project | AI Engineering Bootcamp Batch 10
4
  # Author: 1na37
5
  # ============================================================
 
282
  )
283
  st.markdown("---")
284
 
285
+ # Baca API key langsung dari secrets
286
+ openrouter_key = _read_secret("OPENROUTER_API_KEY")
287
+ gemini_key = _read_secret("GEMINI_API_KEY")
288
+ groq_key = _read_secret("GROQ_API_KEY")
289
+
290
+ # Tampilkan status key (βœ…/❌)
291
+ st.caption(
292
+ f"πŸ”‘ **OpenRouter:** {'βœ…' if openrouter_key else '❌'} "
293
+ f"**Gemini:** {'βœ…' if gemini_key else '❌'} "
294
+ f"**Groq:** {'βœ…' if groq_key else '❌'}"
295
+ )
296
+ if not any([openrouter_key, gemini_key, groq_key]):
297
+ st.warning("⚠️ Tidak ada API key terdeteksi. Chat akan menggunakan fallback.")
298
 
299
  st.markdown("---")
300
  st.markdown(T('sidebar_stack', lang))
 
306
  st.markdown(stack_items[lang])
307
  st.caption(T('sidebar_footer', lang))
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  # ============================================================
310
  # LOAD MODEL & RAG
311
  # ============================================================