Last active
May 17, 2023 02:11
-
-
Save alphasecio/ada075fea283504625cb6b411e6d8413 to your computer and use it in GitHub Desktop.
Load Google Cloud Storage file using LangChain GCSFileLoader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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