This Flask app is a fork from the Modzy Flask Template repository. The code to run this app as is requires connection to Modzy Edge running on localhost:55000
, but you can modify the code to run inferences directly against a Docker container if you wish.
If you followed these instructions for running Modzy Edge on your Raspberry Pi, all you have to do is set up a simple SSH tunnel to connect your local server to the port serving Modzy Edge on the Pi.
ssh -L 55000:localhost:55000 <user@ip-address-of-pi>
Replace <user@ip-address-of-pi>
with the username and IP address of your device. In doing so, your SSH tunnel will connect. Now, follow the below instructions to spin up your Flask App with a connection to your edge device.
The following instructions will generate a simple Python Flask web application that makes inference calls to a Hugging Face Text Classification model running on a Raspberry Pi.
- Download or clone this project from github:
git clone https://github.com/modzy/modzy-edge-hugging-face-raspberry-pi.git
- In your terminal, navigate to the project directory:
cd modzy-edge-hugging-face-raspberry-pi/flask-app
- Install Python
- If you already have Python installed, you may skip this step.
- If you don't have Python installed, install it now. You can download an installer from the Python official website or on a Mac you can install with Homebrew.
- Create and Activate Virtual Environment
- Create virtual environment:
python -m venv venv
- Activate environment
source venv/bin/activate
(Linux & MacOS) or.\venv\Scripts\activate
(Windows)
- Create virtual environment:
- Install Requirements & Set Environment Variables
- Install Python packages by running
pip install -r requirements.txt
- Retrieve your Modzy API key (https://docs.modzy.com/docs/getting-started#key-download-your-api-key)
- Set environment variables:
export API_KEY=<your-api-key>
(Linux/MacOS) or$env:API_KEY="<your-api-key>"
(Windows) - Now start flask with the command
flask run
- Install Python packages by running
- Open your new Web server!
- Using a web browser of your choice, navigate to http://127.0.0.1:5000/
- Type any text into the 'My Text' box and hit Analyze.
- Flask Application code
- config.py: Flask configuration details
- routes.py: Flask App API Endpoints
- HTML Code: Folder containing HTML code