Spaces:
Build error
Build error
Update environment_setup
Browse files- 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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 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 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|