Skip to content

Instantly share code, notes, and snippets.

@alphasecio
alphasecio / search_web.py
Created May 23, 2023 06:50
Search the web using LangChain SerpAPIWrapper.
import streamlit as st
from langchain.utilities import SerpAPIWrapper
# Get SERP API key and the search query
st.subheader('LangChain Search')
serpapi_api_key = st.text_input("SERP API Key", type="password")
search_query = st.text_input("Search Query")
# If the 'Search' button is clicked
if st.button("Search"):
@alphasecio
alphasecio / load_gcs_file.py
Last active May 17, 2023 02:11
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"
@alphasecio
alphasecio / load_youtube_transcripts.py
Created May 17, 2023 01:40
Load YouTube transcripts using LangChain YoutubeLoader
import validators, streamlit as st
from langchain.document_loaders import YoutubeLoader
url = st.text_input("YouTube URL")
if st.button("Load"):
try:
if not url.strip():
st.error("Please enter a URL")
elif not validators.url(url):
@alphasecio
alphasecio / load_url.py
Created May 17, 2023 01:32
Load URL using LangChain UnstructuredURLLoader
import validators, streamlit as st
from langchain.document_loaders import UnstructuredURLLoader
url = st.text_input("Enter URL")
if st.button("Load"):
try:
if not url.strip():
st.error("Please enter a URL")
elif not validators.url(url):
@alphasecio
alphasecio / split_text.py
Created May 17, 2023 01:31
Split text file using LangChain CharacterTextSplitter
import streamlit as st
from langchain.text_splitter import CharacterTextSplitter
text_file = st.file_uploader("Upload text file", type="txt")
if text_file is not None:
text = text_file.read().decode("utf-8")
if st.button("Load"):
try: