david
commited on
Commit
·
9dabbb4
1
Parent(s):
84f799d
gemini api key
Browse files- .gitignore +2 -1
- app.py +7 -3
- example.env +3 -0
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
myenv/
|
|
|
|
1 |
+
myenv/
|
2 |
+
.env
|
app.py
CHANGED
@@ -12,8 +12,12 @@ import google.generativeai as genai
|
|
12 |
# Page configuration
|
13 |
st.set_page_config(layout="wide")
|
14 |
|
|
|
|
|
|
|
|
|
15 |
# Initialize Gemini API
|
16 |
-
genai.configure(api_key=
|
17 |
|
18 |
# Initialize ChromaDB
|
19 |
CHROMA_PATH = "chroma_db"
|
@@ -27,8 +31,8 @@ if 'collection_name' not in st.session_state:
|
|
27 |
if 'chat_history' not in st.session_state:
|
28 |
st.session_state.chat_history = []
|
29 |
|
30 |
-
# Initialize embedding model
|
31 |
-
embedding_model = SentenceTransformer("
|
32 |
|
33 |
def clean_text(text):
|
34 |
return re.sub(r'\s+', ' ', re.sub(r'http\S+', '', text)).strip()
|
|
|
12 |
# Page configuration
|
13 |
st.set_page_config(layout="wide")
|
14 |
|
15 |
+
# 載入 .env
|
16 |
+
load_dotenv()
|
17 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
18 |
+
|
19 |
# Initialize Gemini API
|
20 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
21 |
|
22 |
# Initialize ChromaDB
|
23 |
CHROMA_PATH = "chroma_db"
|
|
|
31 |
if 'chat_history' not in st.session_state:
|
32 |
st.session_state.chat_history = []
|
33 |
|
34 |
+
# Initialize embedding model (中文優化)
|
35 |
+
embedding_model = SentenceTransformer("shibing624/text2vec-base-chinese")
|
36 |
|
37 |
def clean_text(text):
|
38 |
return re.sub(r'\s+', ' ', re.sub(r'http\S+', '', text)).strip()
|
example.env
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Gemini API Key
|
2 |
+
GEMINI_API_KEY=your-gemini-api-key
|
3 |
+
|