Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import logging
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import subprocess
|
|
|
|
| 5 |
|
| 6 |
# Force reinstall Gradio
|
| 7 |
subprocess.run(["pip", "install", "--upgrade", "gradio==4.44.1"])
|
|
@@ -42,18 +43,25 @@ set_debug(True)
|
|
| 42 |
|
| 43 |
# process of getting credentials
|
| 44 |
def get_credentials():
|
| 45 |
-
|
|
|
|
| 46 |
if creds_json_str is None:
|
| 47 |
-
raise ValueError("
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 59 |
|
|
@@ -63,8 +71,10 @@ NEO4J_USERNAME = os.getenv("NEO4J_USERNAME")
|
|
| 63 |
NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
|
| 64 |
NEO4J_DATABASE = os.getenv("NEO4J_DATABASE")
|
| 65 |
|
| 66 |
-
|
| 67 |
-
credentials =
|
|
|
|
|
|
|
| 68 |
embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 69 |
|
| 70 |
### Vector graph search
|
|
|
|
| 2 |
import logging
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import subprocess
|
| 5 |
+
import google.auth
|
| 6 |
|
| 7 |
# Force reinstall Gradio
|
| 8 |
subprocess.run(["pip", "install", "--upgrade", "gradio==4.44.1"])
|
|
|
|
| 43 |
|
| 44 |
# process of getting credentials
|
| 45 |
def get_credentials():
|
| 46 |
+
"""Retrieve Google Cloud credentials from the environment variable and write them to a temporary file."""
|
| 47 |
+
creds_json_str = os.getenv("BOB") # Get JSON credentials stored as a string
|
| 48 |
if creds_json_str is None:
|
| 49 |
+
raise ValueError("Environment variable 'BOB' not found. Please set it with the JSON credentials.")
|
| 50 |
|
| 51 |
+
try:
|
| 52 |
+
# Create a temporary file to store the credentials
|
| 53 |
+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
|
| 54 |
+
temp.write(creds_json_str) # Write the JSON string to the file
|
| 55 |
+
temp_filename = temp.name # Get the temporary file's name
|
| 56 |
+
logging.info(f"Temporary credentials file created at: {temp_filename}")
|
| 57 |
+
return temp_filename
|
| 58 |
+
except Exception as e:
|
| 59 |
+
logging.error(f"Error creating temporary credentials file: {e}")
|
| 60 |
+
raise
|
| 61 |
|
| 62 |
+
# Store the temporary file path
|
| 63 |
+
temp_credentials_file = get_credentials()
|
| 64 |
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = temp_credentials_file
|
| 65 |
|
| 66 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 67 |
|
|
|
|
| 71 |
NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
|
| 72 |
NEO4J_DATABASE = os.getenv("NEO4J_DATABASE")
|
| 73 |
|
| 74 |
+
# Load credentials using google.auth
|
| 75 |
+
credentials, project_id = google.auth.default()
|
| 76 |
+
logging.info(f"Loaded credentials for project: {project_id}")
|
| 77 |
+
|
| 78 |
embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 79 |
|
| 80 |
### Vector graph search
|