Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -3
src/streamlit_app.py
CHANGED
|
@@ -1,14 +1,18 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="AI 新知小助手", page_icon="📚", layout="wide")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
st.stop()
|
| 10 |
|
| 11 |
-
genai.configure(api_key=
|
| 12 |
|
| 13 |
# 1. 定義你要鎖定的 GitHub 檔案清單
|
| 14 |
# 請把 YOUR_ACCOUNT/YOUR_REPO 換成你真實的 GitHub 資訊
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
import requests
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
st.set_page_config(page_title="AI 新知小助手", page_icon="📚", layout="wide")
|
| 7 |
|
| 8 |
+
# 改從環境變數中取得 API Key
|
| 9 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
| 10 |
+
|
| 11 |
+
if not api_key:
|
| 12 |
+
st.error("請確認已經在 Space 的 Settings -> Variables and secrets 中設定了 GEMINI_API_KEY")
|
| 13 |
st.stop()
|
| 14 |
|
| 15 |
+
genai.configure(api_key=api_key)
|
| 16 |
|
| 17 |
# 1. 定義你要鎖定的 GitHub 檔案清單
|
| 18 |
# 請把 YOUR_ACCOUNT/YOUR_REPO 換成你真實的 GitHub 資訊
|