Skip to content

Commit 1f095cc

Browse files
authored
Example loader and bugfixes (#199)
2 parents 188cbb0 + 7eeffc5 commit 1f095cc

File tree

43 files changed

+1341
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1341
-485
lines changed

GCP_DEPLOYMENT.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Run Langflow from a New Google Cloud Project
2+
3+
This guide will help you set up a Langflow development VM in a Google Cloud Platform project using Google Cloud Shell.
4+
5+
> **Note**: When Cloud Shell opens, be sure to select **Trust repo**. Some `gcloud` commands might not run in an ephemeral Cloud Shell environment.
6+
7+
8+
## Standard VM
9+
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial.md)
10+
11+
This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment.
12+
<hr>
13+
14+
## Spot/Preemptible Instance
15+
16+
[![Open in Cloud Shell - Spot Instance](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial.md)
17+
18+
When running as a [spot (preemptible) instance](https://cloud.google.com/compute/docs/instances/preemptible), the code and VM will behave the same way as in a regular instance, executing the startup script to configure the environment, install necessary dependencies, and run the Langflow application. However, **due to the nature of spot instances, the VM may be terminated at any time if Google Cloud needs to reclaim the resources**. This makes spot instances suitable for fault-tolerant, stateless, or interruptible workloads that can handle unexpected terminations and restarts.
19+
20+
## Pricing (approximate)
21+
> For a more accurate breakdown of costs, please use the [**GCP Pricing Calculator**](https://cloud.google.com/products/calculator)
22+
<br>
23+
24+
| Component | Regular Cost (Hourly) | Regular Cost (Monthly) | Spot/Preemptible Cost (Hourly) | Spot/Preemptible Cost (Monthly) | Notes |
25+
| -------------- | --------------------- | ---------------------- | ------------------------------ | ------------------------------- | ----- |
26+
| 100 GB Disk | - | $10/month | - | $10/month | Disk cost remains the same for both regular and Spot/Preemptible VMs |
27+
| VM (n1-standard-4) | $0.15/hr | ~$108/month | ~$0.04/hr | ~$29/month | The VM cost can be significantly reduced using a Spot/Preemptible instance |
28+
| **Total** | **$0.15/hr** | **~$118/month** | **~$0.04/hr** | **~$39/month** | Total costs for running the VM and disk 24/7 for an entire month |

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
~ A User Interface For [LangChain](https://github.com/hwchase17/langchain) ~
66

77
<p>
8+
<a href="https://huggingface.co/spaces/Logspace/LangFlow"><img src="https://huggingface.co/datasets/huggingface/badges/raw/main/open-in-hf-spaces-sm.svg" alt="HuggingFace Spaces"></a>
89
<img alt="GitHub Contributors" src="https://img.shields.io/github/contributors/logspace-ai/langflow" />
910
<img alt="GitHub Last Commit" src="https://img.shields.io/github/last-commit/logspace-ai/langflow" />
1011
<img alt="" src="https://img.shields.io/github/repo-size/logspace-ai/langflow" />
@@ -19,14 +20,31 @@
1920
LangFlow is a GUI for [LangChain](https://github.com/hwchase17/langchain), designed with [react-flow](https://github.com/wbkd/react-flow) to provide an effortless way to experiment and prototype flows with drag-and-drop components and a chat box.
2021

2122
## 📦 Installation
22-
23+
### <b>Locally</b>
2324
You can install LangFlow from pip:
2425

25-
`pip install langflow`
26+
```shell
27+
pip install langflow
28+
```
2629

2730
Next, run:
2831

29-
`langflow`
32+
```shell
33+
python -m langflow
34+
```
35+
or
36+
```shell
37+
langflow
38+
```
39+
40+
### Deploy Langflow on Google Cloud Platform
41+
42+
Follow our step-by-step guide to deploy Langflow on Google Cloud Platform (GCP) using Google Cloud Shell. The guide is available in the [**Langflow in Google Cloud Platform**](GCP_DEPLOYMENT.md) document.
43+
44+
Alternatively, click the **"Open in Cloud Shell"** button below to launch Google Cloud Shell, clone the Langflow repository, and start an **interactive tutorial** that will guide you through the process of setting up the necessary resources and deploying Langflow on your GCP project.
45+
46+
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial_spot.md)
47+
3048

3149
## 🎨 Creating Flows
3250

poetry.lock

Lines changed: 272 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "langflow"
3-
version = "0.0.57"
3+
version = "0.0.58"
44
description = "A Python package with a built-in web application"
55
authors = ["Logspace <[email protected]>"]
66
maintainers = [
@@ -46,6 +46,7 @@ pysrt = "^1.1.2"
4646
fake-useragent = "^1.1.3"
4747
docstring-parser = "^0.15"
4848
psycopg2-binary = "^2.9.6"
49+
pyarrow = "^11.0.0"
4950

5051
[tool.poetry.group.dev.dependencies]
5152
black = "^23.1.0"

scripts/deploy_langflow_gcp.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Set the VM, image, and networking configuration
2+
VM_NAME="langflow-dev"
3+
IMAGE_FAMILY="debian-11"
4+
IMAGE_PROJECT="debian-cloud"
5+
BOOT_DISK_SIZE="100GB"
6+
ZONE="us-central1-a"
7+
REGION="us-central1"
8+
VPC_NAME="default"
9+
SUBNET_NAME="default"
10+
SUBNET_RANGE="10.128.0.0/20"
11+
NAT_GATEWAY_NAME="nat-gateway"
12+
CLOUD_ROUTER_NAME="nat-client"
13+
14+
# Set the GCP project's compute region
15+
gcloud config set compute/region $REGION
16+
17+
# Check if the VPC exists, and create it if not
18+
vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)")
19+
if [[ -z "$vpc_exists" ]]; then
20+
gcloud compute networks create $VPC_NAME --subnet-mode=custom
21+
fi
22+
23+
# Check if the subnet exists, and create it if not
24+
subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)")
25+
if [[ -z "$subnet_exists" ]]; then
26+
gcloud compute networks subnets create $SUBNET_NAME --network=$VPC_NAME --region=$REGION --range=$SUBNET_RANGE
27+
fi
28+
29+
# Create a firewall rule to allow TCP port 8080 for all instances in the VPC
30+
firewall_8080_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-8080" --format="value(name)")
31+
if [[ -z "$firewall_8080_exists" ]]; then
32+
gcloud compute firewall-rules create allow-tcp-8080 --network $VPC_NAME --allow tcp:8080 --source-ranges 0.0.0.0/0 --direction INGRESS
33+
fi
34+
35+
# Create a firewall rule to allow IAP traffic
36+
firewall_iap_exists=$(gcloud compute firewall-rules list --filter="name=allow-iap" --format="value(name)")
37+
if [[ -z "$firewall_iap_exists" ]]; then
38+
gcloud compute firewall-rules create allow-iap --network $VPC_NAME --allow tcp:80,tcp:443 --source-ranges 35.235.240.0/20 --direction INGRESS
39+
fi
40+
41+
# Define the startup script as a multiline Bash here-doc
42+
STARTUP_SCRIPT=$(cat <<'EOF'
43+
#!/bin/bash
44+
45+
# Update and upgrade the system
46+
apt -y update
47+
apt -y upgrade
48+
49+
# Install Python 3 pip, Langflow, and Nginx
50+
apt -y install python3-pip
51+
pip install langflow
52+
apt-get -y install nginx
53+
54+
# Configure Nginx for Langflow
55+
touch /etc/nginx/sites-available/langflow-app
56+
echo "server {
57+
listen 0.0.0.0:8080;
58+
59+
location / {
60+
proxy_pass http://127.0.0.1:7860;
61+
proxy_set_header Host "\$host";
62+
proxy_set_header X-Real-IP "\$remote_addr";
63+
proxy_set_header X-Forwarded-For "\$proxy_add_x_forwarded_for";
64+
}
65+
}" >> /etc/nginx/sites-available/langflow-app
66+
ln -s /etc/nginx/sites-available/langflow-app /etc/nginx/sites-enabled/
67+
sudo nginx -t
68+
sudo systemctl restart nginx
69+
langflow
70+
EOF
71+
)
72+
73+
# Create a temporary file to store the startup script
74+
tempfile=$(mktemp)
75+
echo "$STARTUP_SCRIPT" > $tempfile
76+
77+
# Create the VM instance with the specified configuration and startup script
78+
gcloud compute instances create $VM_NAME \
79+
--image-family $IMAGE_FAMILY \
80+
--image-project $IMAGE_PROJECT \
81+
--boot-disk-size $BOOT_DISK_SIZE \
82+
--machine-type=n1-standard-4 \
83+
--metadata-from-file startup-script=$tempfile \
84+
--zone $ZONE \
85+
--network $VPC_NAME \
86+
--subnet $SUBNET_NAME
87+
88+
# Remove the temporary file after the VM is created
89+
rm $tempfile

scripts/deploy_langflow_gcp_spot.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Set the VM, image, and networking configuration
2+
VM_NAME="langflow-dev"
3+
IMAGE_FAMILY="debian-11"
4+
IMAGE_PROJECT="debian-cloud"
5+
BOOT_DISK_SIZE="100GB"
6+
ZONE="us-central1-a"
7+
REGION="us-central1"
8+
VPC_NAME="default"
9+
SUBNET_NAME="default"
10+
SUBNET_RANGE="10.128.0.0/20"
11+
NAT_GATEWAY_NAME="nat-gateway"
12+
CLOUD_ROUTER_NAME="nat-client"
13+
14+
# Set the GCP project's compute region
15+
gcloud config set compute/region $REGION
16+
17+
# Check if the VPC exists, and create it if not
18+
vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)")
19+
if [[ -z "$vpc_exists" ]]; then
20+
gcloud compute networks create $VPC_NAME --subnet-mode=custom
21+
fi
22+
23+
# Check if the subnet exists, and create it if not
24+
subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)")
25+
if [[ -z "$subnet_exists" ]]; then
26+
gcloud compute networks subnets create $SUBNET_NAME --network=$VPC_NAME --region=$REGION --range=$SUBNET_RANGE
27+
fi
28+
29+
# Create a firewall rule to allow TCP port 8080 for all instances in the VPC
30+
firewall_8080_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-8080" --format="value(name)")
31+
if [[ -z "$firewall_8080_exists" ]]; then
32+
gcloud compute firewall-rules create allow-tcp-8080 --network $VPC_NAME --allow tcp:8080 --source-ranges 0.0.0.0/0 --direction INGRESS
33+
fi
34+
35+
# Create a firewall rule to allow IAP traffic
36+
firewall_iap_exists=$(gcloud compute firewall-rules list --filter="name=allow-iap" --format="value(name)")
37+
if [[ -z "$firewall_iap_exists" ]]; then
38+
gcloud compute firewall-rules create allow-iap --network $VPC_NAME --allow tcp:80,tcp:443 --source-ranges 35.235.240.0/20 --direction INGRESS
39+
fi
40+
41+
# Define the startup script as a multiline Bash here-doc
42+
STARTUP_SCRIPT=$(cat <<'EOF'
43+
#!/bin/bash
44+
45+
# Update and upgrade the system
46+
apt -y update
47+
apt -y upgrade
48+
49+
# Install Python 3 pip, Langflow, and Nginx
50+
apt -y install python3-pip
51+
pip install langflow
52+
apt-get -y install nginx
53+
54+
# Configure Nginx for Langflow
55+
touch /etc/nginx/sites-available/langflow-app
56+
echo "server {
57+
listen 0.0.0.0:8080;
58+
59+
location / {
60+
proxy_pass http://127.0.0.1:7860;
61+
proxy_set_header Host "\$host";
62+
proxy_set_header X-Real-IP "\$remote_addr";
63+
proxy_set_header X-Forwarded-For "\$proxy_add_x_forwarded_for";
64+
}
65+
}" >> /etc/nginx/sites-available/langflow-app
66+
ln -s /etc/nginx/sites-available/langflow-app /etc/nginx/sites-enabled/
67+
sudo nginx -t
68+
sudo systemctl restart nginx
69+
langflow
70+
EOF
71+
)
72+
73+
# Create a temporary file to store the startup script
74+
tempfile=$(mktemp)
75+
echo "$STARTUP_SCRIPT" > $tempfile
76+
77+
# Create the VM instance with the specified configuration and startup script
78+
gcloud compute instances create $VM_NAME \
79+
--image-family $IMAGE_FAMILY \
80+
--image-project $IMAGE_PROJECT \
81+
--boot-disk-size $BOOT_DISK_SIZE \
82+
--machine-type=n1-standard-4 \
83+
--metadata-from-file startup-script=$tempfile \
84+
--zone $ZONE \
85+
--network $VPC_NAME \
86+
--subnet $SUBNET_NAME \
87+
-preemptible
88+
89+
# Remove the temporary file after the VM is created
90+
rm $tempfile

scripts/walkthroughtutorial.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Deploy Langflow on Google Cloud Platform
2+
3+
**Duration**: 45 minutes
4+
**Author**: [Robert Wilkins III](https://www.linkedin.com/in/robertwilkinsiii)
5+
6+
## Introduction
7+
8+
In this tutorial, you will learn how to deploy Langflow on [Google Cloud Platform](https://cloud.google.com/) (GCP) using Google Cloud Shell.
9+
10+
This tutorial assumes you have a GCP account and basic knowledge of Google Cloud Shell. If you're not familiar with Cloud Shell, you can review the [Cloud Shell documentation](https://cloud.google.com/shell/docs).
11+
12+
## Set up your environment
13+
14+
Before you start, make sure you have the following prerequisites:
15+
16+
- A GCP account with the necessary permissions to create resources
17+
- A project on GCP where you want to deploy Langflow
18+
19+
[**Select your GCP project**]<walkthrough-project-setup
20+
billing="true"
21+
apis="compute.googleapis.com,container.googleapis.com">
22+
</walkthrough-project-setup>
23+
24+
25+
In the next step, you'll configure the GCP environment and deploy Langflow.
26+
27+
## Configure the GCP environment and deploy Langflow
28+
Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow:
29+
30+
```sh
31+
gcloud config set project <walkthrough-project-id/>
32+
bash ./deploy_langflow_gcp.sh
33+
```
34+
35+
The script will:
36+
37+
1. Check if the required resources (VPC, subnet, firewall rules, and Cloud Router) exist and create them if needed
38+
2. Create a startup script to install Python, Langflow, and Nginx
39+
3. Create a Compute Engine VM instance with the specified configuration and startup script
40+
4. Configure Nginx to serve Langflow on TCP port 8080
41+
42+
<walkthrough-pin-section-icon></walkthrough-pin-section-icon>
43+
> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished.
44+
45+
In the next step, you'll learn how to connect to the Langflow VM.
46+
47+
## Connect to the Langflow VM
48+
To connect to your new Langflow VM, follow these steps:
49+
50+
1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080
51+
<br>**or**
52+
3. Run the following command to display the URL for your Langflow environment:
53+
```bash
54+
export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)")
55+
56+
echo http://$LANGFLOW_IP:8080
57+
```
58+
59+
4. Click on the Langflow URL in cloudshell to be greeted by the Langflow Dev environment
60+
61+
Congratulations! You have successfully deployed Langflow on Google Cloud Platform.
62+
63+
<walkthrough-conclusion-trophy></walkthrough-conclusion-trophy>
64+
65+
## Cleanup
66+
If you want to remove the resources created during this tutorial, you can use the following commands:
67+
68+
```sql
69+
gcloud compute instances delete langflow-dev --zone us-central1-a --quiet
70+
```
71+
The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place.
72+
73+
However, if you decide to remove them after completing the walkthrough, you can use the following gcloud commands:
74+
75+
<walkthrough-pin-section-icon></walkthrough-pin-section-icon>
76+
> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings.
77+
78+
```
79+
gcloud compute firewall-rules delete allow-tcp-8080 --quiet
80+
81+
gcloud compute firewall-rules delete allow-iap --quiet
82+
83+
gcloud compute networks subnets delete default --region us-central1 --quiet
84+
85+
gcloud compute networks delete default --quiet
86+
```

0 commit comments

Comments
 (0)