Skip to content

Instantly share code, notes, and snippets.

@alphasecio
Last active May 17, 2023 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphasecio/ada075fea283504625cb6b411e6d8413 to your computer and use it in GitHub Desktop.
Save alphasecio/ada075fea283504625cb6b411e6d8413 to your computer and use it in GitHub Desktop.
Load Google Cloud Storage file using LangChain GCSFileLoader
import os, streamlit as st
from langchain.document_loaders import GCSFileLoader
creds_file = st.file_uploader("Upload Google Cloud credentials file", type="json")
if creds_file is not None:
creds_contents = creds_file.read().decode("utf-8")
with open("temp_credentials.json", "w") as f:
f.write(creds_contents)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "temp_credentials.json"
if st.button("Load"):
try:
loader = GCSFileLoader(project_name="langchain-gcs", bucket="langchain-gcs", blob="lorem-ipsum.txt")
data = loader.load()
st.success(data)
except Exception as e:
st.error(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment