This is a full stack application with a frontend built in React and a backend in Python Flask.
The project is divided into two main parts:
frontend
: This directory contains the React app.backend
: This directory contains the Flask app that uses Langchain to query OpenAI.
To set up and start the backend server, follow these steps:
-
Navigate to the backend directory.
cd backend
-
Create a Python virtual environment and activate it.
python3 -m venv venv source venv/bin/activate
-
Install the required Python packages.
pip install -r requirements.txt
-
Start the Flask app. It will run on port 5001.
export FLASK_APP=app.py export FLASK_ENV=development flask run --port=5001
To start the frontend React app, follow these steps:
-
Navigate to the frontend directory.
cd frontend
-
Install the required packages.
npm install
-
Start the React app. Note: it proxies requests to backend server at port 5001.
npm run start
To prepare the application for production, follow these steps:
-
Navigate to the frontend directory and build the React app.
cd frontend npm run build
-
This creates a
build
directory inside the frontend directory with a production build of your React app. Now, start the Flask app in production mode:cd ../backend export FLASK_APP=app.py flask run --port=5001
To deploy the application using Docker, use the Dockerfile in the project root. This will create a Docker image with the Flask backend serving the React frontend. The application inside the Docker container will be available on port 5001.
- Build the Docker image.
docker build -t python-react-app .
- Run the Docker container.
docker run -p 5001:5001 -e OPENAI_API_KEY="" -e PINECONE_ENVIRONMENT="" -e PINECONE_API_KEY="" python-react-app