-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added local tensorflow image tagging. You can choose between th…
…at or cloud based clarifai!
- Loading branch information
1 parent
b6d489e
commit 648633e
Showing
15 changed files
with
252 additions
and
149 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
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
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 |
---|---|---|
@@ -1,27 +1,9 @@ | ||
root - INFO - You should go to the homepage and set the config. | ||
root - INFO - Initiating NotionAI Class. | ||
root - INFO - Initiating with a found config file. | ||
root - INFO - Running notionAI with {'url': 'https://www.notion.so/glassear/d4e43dbfe7244e0a83f18e14506e74ae?v=2b6755006a15418c978d5067180baae0', 'token': 'e6517083645826700a071fdf1644a844b6a9dba7252010c8a99efaae991f990575fd6160ce2c9a30c9ed78057261bb49f3245e227d80c3a8a630f3f4e839e66d90d75c24a26671a29fc072020f6d'} | ||
root - INFO - Using tensorflow predictor, with delete_after_tagging = True | ||
root - INFO - Initiating with a found port.json file. | ||
root - INFO - Using 8080 port | ||
werkzeug - WARNING - * Debugger is active! | ||
werkzeug - INFO - * Debugger PIN: 207-644-306 | ||
werkzeug - INFO - * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit) | ||
root - INFO - Adding url to mind: b'https://github.com/elblogbruno/NotionAI-MyMind' b'elblogbruno/NotionAI-MyMind: This repo uses AI and the wonderful Notion to enable you to add anything on the web to your "Mind" and forget about everything else.' | ||
werkzeug - INFO - 192.168.1.42 - - [30/Jan/2021 11:09:39] "[35m[1mGET /add_url_to_mind?url=https://github.com/elblogbruno/NotionAI-MyMind&title=elblogbruno/NotionAI-MyMind:%20This%20repo%20uses%20AI%20and%20the%20wonderful%20Notion%20to%20enable%20you%20to%20add%20anything%20on%20the%20web%20to%20your%20%22Mind%22%20and%20forget%20about%20everything%20else. HTTP/1.1[0m" 500 - | ||
werkzeug - ERROR - 192.168.1.42 - - [30/Jan/2021 11:10:13] code 400, message Bad request version ('��\x13\x01\x13\x02\x13\x03�+�/�,�0̨̩�\x13�\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93��\x00\x00\x00\x17\x00\x00�\x01\x00\x01\x00\x00') | ||
werkzeug - ERROR - 192.168.1.42 - - [30/Jan/2021 11:10:13] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x02\x00\x01\x00\x01�\x03\x032��\x9e�P�\x92�\x88\x94\x10��\x7f�\x80\x80��,B\x82\x02_��') | ||
werkzeug - ERROR - 192.168.1.42 - - [30/Jan/2021 11:10:13] code 400, message Bad request version ('Ȧ\x0e��V���\x9c�\x98�x\x83') | ||
werkzeug - ERROR - 192.168.1.42 - - [30/Jan/2021 11:10:13] code 400, message Bad request version ('2-\x07³�\x0f�w\x13�۬$�\\\x00"JJ\x13\x01\x13\x02\x13\x03�+�/�,�0̨̩�\x13�\x14\x00\x9c\x00\x9d\x00/\x005\x00') | ||
werkzeug - INFO - 192.168.1.42 - - [30/Jan/2021 11:10:18] "[37mGET / HTTP/1.1[0m" 200 - | ||
root - INFO - Running notionAI with {'url': 'https://www.notion.so/glassear/d4e43dbfe7244e0a83f18e14506e74ae?v=2b6755006a15418c978d5067180baae0', 'token': 'e6517083645826700a071fdf1644a844b6a9dba7252010c8a99efaae991f990575fd6160ce2c9a30c9ed78057261bb49f3245e227d80c3a8a630f3f4e839e66d90d75c24a26671a29fc072020f6d', 'clarifai_key': '7d13a00d87c5408b96fa94d16ad3c521'} | ||
werkzeug - INFO - 192.168.1.42 - - [30/Jan/2021 11:10:24] "[37mPOST /handle_data HTTP/1.1[0m" 200 - | ||
root - INFO - Adding url to mind: b'https://github.com/elblogbruno/NotionAI-MyMind' b'elblogbruno/NotionAI-MyMind: This repo uses AI and the wonderful Notion to enable you to add anything on the web to your "Mind" and forget about everything else.' | ||
root - INFO - {"type": "block", "blockId": "d4e43dbf-e724-4e0a-83f1-8e14506e74ae", "property": "P#~d", "items": [{"url": "https://github.com/elblogbruno/NotionAI-MyMind", "title": "elblogbruno/NotionAI-MyMind: This repo uses AI and the wonderful Notion to enable you to add anything on the web to your \"Mind\" and forget about everything else."}], "from": "chrome"} | ||
root - INFO - Thread 058a46df-5f41-401e-be3f-f197d2112859: starting | ||
werkzeug - INFO - 192.168.1.42 - - [30/Jan/2021 11:10:30] "[37mGET /add_url_to_mind?url=https://github.com/elblogbruno/NotionAI-MyMind&title=elblogbruno/NotionAI-MyMind:%20This%20repo%20uses%20AI%20and%20the%20wonderful%20Notion%20to%20enable%20you%20to%20add%20anything%20on%20the%20web%20to%20your%20%22Mind%22%20and%20forget%20about%20everything%20else. HTTP/1.1[0m" 200 - | ||
root - INFO - No content available yet 0 | ||
root - INFO - No content available yet 1 | ||
root - INFO - No content available yet 2 | ||
root - INFO - None | ||
root - INFO - Request failed, status code: 10020 | ||
root - INFO - Thread 058a46df-5f41-401e-be3f-f197d2112859: finishing | ||
root - INFO - Adding url to mind: b'chrome-extension://ocjdfdihgfjfflddjlkohpeifglmibig/options.html?serverip=http://192.168.1.42:8080/' b'Notion AI My Mind Options!' | ||
werkzeug - INFO - 192.168.1.42 - - [30/Jan/2021 11:11:59] "[35m[1mGET /add_url_to_mind?url=chrome-extension://ocjdfdihgfjfflddjlkohpeifglmibig/options.html?serverip=http%3A%2F%2F192.168.1.42%3A8080%2F&title=Notion%20AI%20My%20Mind%20Options! HTTP/1.1[0m" 500 - |
Binary file added
BIN
+1.51 KB
Python Server/app/image_tagging/__pycache__/image_tagging.cpython-38.pyc
Binary file not shown.
File renamed without changes.
Binary file added
BIN
+1.67 KB
Python Server/app/image_tagging/clarifai_tagging/__pycache__/ClarifaiAI.cpython-38.pyc
Binary file not shown.
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,32 @@ | ||
from image_tagging.clarifai_tagging.ClarifaiAI import ClarifaiAI | ||
from image_tagging.tensorflow_tagging.tensorflow_tagging import TensorFlowTag | ||
import json | ||
|
||
|
||
class ImageTagging: | ||
|
||
def __init__(self,data,logging): | ||
options = {} | ||
with open('options.json') as json_file: | ||
options = json.load(json_file) | ||
try: | ||
self.options = options | ||
if options['use_clarifai']: | ||
self.predictor = ClarifaiAI(data['clarifai_key']) | ||
logging.info("Using clarifai predictor") | ||
else: | ||
self.predictor = TensorFlowTag(options['delete_after_tagging']) | ||
logging.info("Using tensorflow predictor, with delete_after_tagging = {}".format(options['delete_after_tagging'])) | ||
except FileNotFoundError: | ||
logging.info("options.json not found") | ||
print("Wrong file or file path") | ||
|
||
def get_tags(self, image_url): | ||
self.print_current_detector() | ||
return self.predictor.get_tags(image_url) | ||
|
||
def print_current_detector(self): | ||
if self.options['use_clarifai']: | ||
print("Using clarifai predictor") | ||
else: | ||
print("Using tensorflow predictor, with delete_after_tagging = {}".format(self.options['delete_after_tagging'])) |
Binary file added
BIN
+1.77 KB
...Server/app/image_tagging/tensorflow_tagging/__pycache__/tensorflow_tagging.cpython-38.pyc
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
Python Server/app/image_tagging/tensorflow_tagging/tensorflow_tagging.py
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 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
|
||
from tensorflow.python.keras.applications.inception_v3 import InceptionV3, preprocess_input, decode_predictions | ||
from tensorflow.python.keras.preprocessing import image | ||
import os | ||
from utils import download_image_from_url, createFolder | ||
|
||
|
||
class TensorFlowTag: | ||
|
||
def __init__(self, delete_image_after_tagging=True): | ||
self.delete_after_tagging = delete_image_after_tagging | ||
|
||
createFolder("./image_tagging/temp_image_folder") | ||
|
||
def get_tags(self, image_url): | ||
model = InceptionV3(weights='imagenet') | ||
file = download_image_from_url(image_url) | ||
img = image.load_img(file, target_size=(299, 299)) | ||
x = image.img_to_array(img) | ||
x = np.expand_dims(x, axis=0) | ||
x = preprocess_input(x) | ||
|
||
preds = model.predict(x) | ||
prediction_decoded = decode_predictions(preds, top=5)[0] | ||
|
||
print('Predicted:', prediction_decoded) | ||
|
||
tags = [] | ||
for element in prediction_decoded: | ||
tags.append(element[1]) | ||
|
||
if self.delete_after_tagging: | ||
os.remove(file) | ||
|
||
str1 = ','.join(str(e) for e in tags) | ||
|
||
return str1 |
Binary file not shown.
Oops, something went wrong.