-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from scramjetorg/feat/new_samples
add fire sequence
- Loading branch information
Showing
13 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Sequence sends forest images to the fire detecting machine learning API. | ||
___ | ||
|
||
|
||
## Running | ||
|
||
> ❗ Remember to [setup transform-hub locally](https://docs.scramjet.org/platform/self-hosted-installation) or use the [platform's environment](https://docs.scramjet.org/platform/quick-start) for the sequence deployment. | ||
Open two terminals and run the following commands: | ||
|
||
|
||
```bash | ||
# go to 'seq-fire-alert' directory | ||
cd python/seq-fire-alert | ||
|
||
# build | ||
npm run build | ||
``` | ||
|
||
If you run this sample on Self Hosted Hub, please start it with process adapter option: | ||
|
||
```bash | ||
DEVELOPMENT=1 sth --runtime-adapter=process | ||
``` | ||
|
||
Once you've built it, you need to deploy it. | ||
|
||
```bash | ||
si seq deploy dist | ||
``` | ||
|
||
|
||
Now you should be able to see on the parameters on topic "fire": | ||
|
||
```bash | ||
si topic get pi |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
from scramjet.streams import Stream | ||
import aiohttp | ||
import os | ||
|
||
|
||
API_BASE = 'https://forestapi.bieda.it' | ||
IMAGE_DIR = '/Users/spiderman/raspberry-pi-dash/seq-fire-alert/images' | ||
|
||
provides = { | ||
'provides': 'fire', | ||
'contentType': 'text/plain' | ||
} | ||
|
||
def get_bytes(path): | ||
with open(path, 'rb') as f: | ||
data = f.read() | ||
return data | ||
|
||
async def post(data, url): | ||
async with aiohttp.ClientSession() as session: | ||
form_data = aiohttp.FormData() | ||
form_data.add_field('file', data) | ||
url = f'{API_BASE}/{url}' | ||
async with session.post(url, data=form_data) as response: | ||
return await response.json() | ||
|
||
async def main(stream): | ||
for file in os.listdir(f'{IMAGE_DIR}'): | ||
image = get_bytes(f'{IMAGE_DIR}/{file}') | ||
response = await post(image, 'predict') | ||
stream.write([response]) | ||
stream.write(['some actions...']) | ||
await asyncio.sleep(3) | ||
|
||
async def run(context, input): | ||
stream = Stream() | ||
asyncio.gather(main(stream), return_exceptions=True) | ||
return stream.map(lambda x : str(x) + "\n") | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@scramjet/fire-alert", | ||
"version": "0.0.1", | ||
"main": "main.py", | ||
"author": "mcdominik", | ||
"license": "GPL-3.0", | ||
"description": "raspberry pi internal parameters fetcher example", | ||
"keywords": [ | ||
"fire", | ||
"python", | ||
"machine learning", | ||
"topics" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/scramjetorg/platform-samples" | ||
}, | ||
"engines": { | ||
"python3": "3.8.0" | ||
}, | ||
"scripts": { | ||
"build": "mkdir -p dist/__pypackages__/ && pip3 install -t dist/__pypackages__/ -r requirements.txt && cp main.py package.json ./dist/", | ||
"pack" : "si seq pack dist", | ||
"clean": "rm -rf ./dist" | ||
}, | ||
"dependencies": { | ||
"@scramjet/api-client": "0.32.1" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
scramjet-framework-py==0.10 | ||
pyee==9.0.4 | ||
aiohttp==3.8.4 |