Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove receiver, add scraper, few mods #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions functions/image-processor/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ def setup_img_path(media_url):
return '/tmp/poster_%s.jpeg' % h.hexdigest()


def post_media(slack_client, slack_channel,
filename, entities, status, log):
def post_media(slack_client, slack_channel, filename, entities, status, log):
medias = entities.get("media", [])
for media in medias:
if "media_url_https" in media:
Expand All @@ -197,8 +196,7 @@ def post_media(slack_client, slack_channel,
slack_client, slack_channel, filename, url, status
)
if "ok" in response and response["ok"]:
log.info("message posted to Slack successfully "
"from image: {0}".format(url))
log.info("message posted to Slack successfully from image: {0}".format(url))
else:
if "headers" in response:
hs = response["headers"]
Expand All @@ -213,8 +211,7 @@ def post_media(slack_client, slack_channel,
raise Exception(ujson.dumps(response))


def post_image_to_slack(slack_client, slack_channel,
filename, img_url, status):
def post_image_to_slack(slack_client, slack_channel,filename, img_url, status):
return slack_client.api_call(
"chat.postMessage",
channel=slack_channel,
Expand Down Expand Up @@ -301,17 +298,15 @@ def add_fn_logo(img):
return cv.cvtColor(np.array(img_pil), cv.COLOR_RGB2BGR)


def process_single_media_file(ctx, sess, media_url, label_map,
event_id, event_type, ran_on):
def process_single_media_file(ctx, sess, media_url, label_map, event_id, event_type, ran_on):
log = get_logger(ctx)
scores = []
classes = []
img, out = process_media(sess, media_url, log)
num_detections = int(out[0][0])
log.info("detection completed, objects found: %s" % num_detections)
for i in range(num_detections):
class_id, score, img = process_detection(
out, img, label_map, i, log)
class_id, score, img = process_detection(out, img, label_map, i, log)
scores.append(score)
classes.append(class_id)

Expand All @@ -331,33 +326,33 @@ def process_single_media_file(ctx, sess, media_url, label_map,


def with_graph(label_map):

sess = tf.Session()
sess.graph.as_default()

def fn(ctx, data=None, loop=None):
log = get_logger(ctx)
log.info("tf graph imported")

if data is not None or len(data) !=0:
data = ujson.loads(data)
log.info("incoming data: {0}".format(ujson.dumps(data)))
media = data.get("media", [])
event_id = data.get("event_id")
event_type = data.get("event_type", "")
if event_type.startswith("Microsoft"):
event_type = "Azure"
event_id = event_id.replace("-", "")
ran_on = data.get("ran_on", "Fn Project on Oracle Cloud")

for media_url in media:
img, status = process_single_media_file(
ctx, sess, media_url, label_map,
event_id, event_type, ran_on
)

post_image(ctx, status, media_url, add_fn_logo(img))
else:
log.info("missing data")
# media = data.get("media", [])
event_id = data.get("id")
event_type = data.get("type", "")
photo_url = data.get("data").get("photo_url")

# if event_type.startswith("Microsoft"):
# event_type = "Azure"
# event_id = event_id.replace("-", "")

ran_on = data.get("ran_on", "Fn Project")

img, status = process_single_media_file(
ctx, sess, photo_url, label_map,
event_id, event_type, ran_on
)
post_image(ctx, status, photo_url, add_fn_logo(img))

return fn

Expand Down
5 changes: 1 addition & 4 deletions functions/image-processor/func.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
schema_version: 20180708
name: image-processor
version: 0.0.101
version: 0.0.109
runtime: docker
format: http-stream
memory: 1024
timeout: 300
idle_timeout: 300
config:
DETECT_SENSITIVITY: "0.3"
IS_DOCKER4MAC_LOCAL: "true"
expects:
config:
- name: DETECT_SENSITIVITY
Expand All @@ -21,8 +20,6 @@ expects:
required: true
- name: TWITTER_ACCESS_TOKEN_SECRET
required: true
- name: IS_DOCKER4MAC_LOCAL
required: false
- name: SLACK_API_TOKEN
required: true
- name: SLACK_CHANNEL
Expand Down
28 changes: 0 additions & 28 deletions functions/image-processor/func.yaml.bak

This file was deleted.

11 changes: 11 additions & 0 deletions functions/image-processor/payload.ce.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"specversion":"0.2",
"type":"cloudevent.flickr.image",
"source":"scraper",
"id":"my-id",
"contenttype":"application\/json",
"data":{
"photo_url":"https:\/\/farm2.staticflickr.com\/1051\/1154370504_58bafbc654_c.jpg"
},
"extensions":{}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"media": [
"http://survivingchurch.org/wp-content/uploads/2016/10/Donald-Trump-Photos-HD-1024x768.png",
"http://2wk128489wjq47m3kwxwe9hh.wpengine.netdna-cdn.com/wp-content/uploads/2014/10/hotdog_mustard-main.jpg",
"https://i.ytimg.com/vi/Lu8lDgKInSM/hqdefault.jpg",
"http://survivingchurch.org/wp-content/uploads/2016/10/Donald-Trump-Photos-HD-1024x768.png",
"https://www.dairyqueen.com/Global/Food/Hot-Dogs_8-to-1_470x500.jpg",
"https://pbs.twimg.com/profile_images/625802912887783424/_uzj-IZ4.jpg",
"https://i.ytimg.com/vi/lFarE1hH0ss/maxresdefault.jpg",
"https://i.ytimg.com/vi/lFarE1hH0ss/maxresdefault.jpg"
],
"media_test": [
"https://i.ytimg.com/vi/Lu8lDgKInSM/hqdefault.jpg",
"http://m.step.aero/Burningman_2017_gifting_plane_rides.jpg",
"http://m.step.aero/Burningman_2017_raising_and_rigging.jpg",
"http://m.step.aero/Chad's%20Dog.png"
],
"media_test": [
"http://survivingchurch.org/wp-content/uploads/2016/10/Donald-Trump-Photos-HD-1024x768.png"
],
"event_id": "test_id",
"event_type": "test_type",
"ran_on": "<fn-hostname-or-dns>"
}
}
18 changes: 0 additions & 18 deletions functions/receiver/Gopkg.lock

This file was deleted.

8 changes: 0 additions & 8 deletions functions/receiver/Gopkg.toml

This file was deleted.

38 changes: 0 additions & 38 deletions functions/receiver/aws.go

This file was deleted.

28 changes: 0 additions & 28 deletions functions/receiver/cloudevent.go

This file was deleted.

106 changes: 0 additions & 106 deletions functions/receiver/func.go

This file was deleted.

Loading