felixflier03 commited on
Commit
417616a
·
verified ·
1 Parent(s): f0473ab

Update environment_setup

Browse files
Files changed (1) hide show
  1. environment_setup +43 -26
environment_setup CHANGED
@@ -1,35 +1,52 @@
1
- # environment_setup.py
2
  import os
3
  import streamlit as st
4
  import gdown
5
  from pathlib import Path
6
 
7
  def setup_environment():
8
- # Pfade definieren
9
- BASE_PATH = Path(__file__).resolve().parent
10
- VECTOR_STORE_PATH = BASE_PATH / "vector_stores"
11
- VECTOR_STORE_PATH.mkdir(parents=True, exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Google Drive File ID für vectorstore.pkl
14
- VECTOR_STORE_FILE_ID = "1EAzau2hzMTu-f4ncCXaD9933HTay2o_8" # Ersetzen Sie dies mit Ihrer File-ID
15
- VECTOR_STORE_FILE = VECTOR_STORE_PATH / "vectorstore.pkl"
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- # Nur vectorstore.pkl von Google Drive laden, wenn sie noch nicht existiert
18
- if not VECTOR_STORE_FILE.exists():
19
- try:
20
- gdown.download(
21
- f"https://drive.google.com/uc?id={VECTOR_STORE_FILE_ID}",
22
- str(VECTOR_STORE_FILE),
23
- quiet=False
24
- )
25
- except Exception as e:
26
- st.error(f"Fehler beim Laden der Vector Store Datei: {str(e)}")
27
- raise
28
 
29
- # API Key aus Hugging Face Secrets
30
- api_key = os.environ.get('GOOGLE_API_KEY')
31
- if not api_key:
32
- st.error("Google API Key nicht gefunden in HF Secrets!")
33
- raise ValueError("API Key fehlt")
34
-
35
- return api_key, VECTOR_STORE_PATH
 
 
1
  import os
2
  import streamlit as st
3
  import gdown
4
  from pathlib import Path
5
 
6
  def setup_environment():
7
+ """Setup der Umgebung für die Anwendung"""
8
+ try:
9
+ # Pfade definieren
10
+ BASE_PATH = Path(__file__).resolve().parent
11
+ VECTOR_STORE_PATH = BASE_PATH / "vector_stores"
12
+ VECTOR_STORE_PATH.mkdir(parents=True, exist_ok=True)
13
+
14
+ # Google Drive File ID für vectorstore.pkl
15
+ VECTOR_STORE_FILE = VECTOR_STORE_PATH / "vectorstore.pkl"
16
+ GDRIVE_FILE_ID = "YOUR_GOOGLE_DRIVE_FILE_ID" # Ersetzen Sie dies mit Ihrer File-ID
17
+
18
+ # Prüfe ob wir in Hugging Face Spaces sind
19
+ is_hf_space = "SPACE_ID" in os.environ
20
+
21
+ if is_hf_space and not VECTOR_STORE_FILE.exists():
22
+ try:
23
+ # Lade von Google Drive nur wenn nötig
24
+ gdown.download(
25
+ f"https://drive.google.com/uc?id={GDRIVE_FILE_ID}",
26
+ str(VECTOR_STORE_FILE),
27
+ quiet=False
28
+ )
29
+ except Exception as e:
30
+ st.error(f"Fehler beim Laden der Vector Store Datei: {str(e)}")
31
+ raise
32
 
33
+ # API Key aus Hugging Face Secrets oder lokaler Umgebung
34
+ if is_hf_space:
35
+ api_key = os.environ.get('GOOGLE_API_KEY')
36
+ if not api_key:
37
+ st.error("Google API Key nicht gefunden in HF Secrets!")
38
+ raise ValueError("API Key fehlt")
39
+ else:
40
+ # Lokale Entwicklung - nutze .env oder direkte Umgebungsvariable
41
+ from dotenv import load_dotenv
42
+ load_dotenv()
43
+ api_key = os.environ.get('GOOGLE_API_KEY')
44
+ if not api_key:
45
+ st.error("Google API Key nicht in Umgebungsvariablen gefunden!")
46
+ raise ValueError("API Key fehlt")
47
 
48
+ return api_key, VECTOR_STORE_PATH
 
 
 
 
 
 
 
 
 
 
49
 
50
+ except Exception as e:
51
+ st.error(f"Fehler beim Setup der Umgebung: {str(e)}")
52
+ raise