diff --git a/pcloudcv/Classification Visualization.ipynb b/pcloudcv/Classification Visualization.ipynb index 10f954c..4efdffa 100644 --- a/pcloudcv/Classification Visualization.ipynb +++ b/pcloudcv/Classification Visualization.ipynb @@ -1,104 +1,120 @@ { - "metadata": { - "name": "", - "signature": "sha256:e5a7dea9a46aee4046b69de57cd156cb43fe8334c595a4b61dc397875aaf5867" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ + "cells": [ { - "cells": [ - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Start by importing PCloudCV module to run Python API for cloudcv" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from pcloudcv import PCloudCV\n", - "import utility.job as uj\n", - "from IPython.display import display\n", - "from IPython.display import display_pretty, display_html, display_jpeg, display_png, display_json, display_latex, display_svg\n", - "from IPython.display import Image\n", - "from IPython.display import HTML\n", - "import json\n", - "import os" - ], - "language": "python", - "metadata": {}, - "outputs": [] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Load the configuration file and mention the function you wish to run" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "config_path = os.path.join(os.getcwd(), 'config.json') #full path of the config.json file\n", - "dict = {'exec': 'classify'}" - ], - "language": "python", - "metadata": {}, - "outputs": [] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Start CloudCV Thread" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Starting the CloudCV is as easy initializing the class with the config file path, dictionary containing parameters and a flag specifying whether to login through google or not.\n" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "p = PCloudCV(config_path, dict, True)\n", - "p.start()" - ], - "language": "python", - "metadata": {}, - "outputs": [] - }, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Start by importing PCloudCV module to run Python API for cloudcv" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Visualize Results Here" + "name": "stdout", + "output_type": "stream", + "text": [ + "Added Path: /home/haswi/git/pcloudcv/pcloudcv\n" ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from IPython.display import HTML\n", - "HTML('')\n" - ], - "language": "python", - "metadata": {}, - "outputs": [] } ], - "metadata": {} + "source": [ + "from pcloudcv import PCloudCV\n", + "import utility.job as uj\n", + "from IPython.display import display\n", + "import json\n", + "import os" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load the configuration file and mention the function you wish to run" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "config_path = os.path.join(os.getcwd(), 'config.json') #full path of the config.json file\n", + "dict = {'exec': 'classify'}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Start CloudCV Thread" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Starting the CloudCV is as easy initializing the class with the config file path, dictionary containing parameters and a flag specifying whether to login through google or not.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "p = PCloudCV(config_path, dict, True)\n", + "p.start()\n", + "p.join()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Visualize Results Here" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from IPython.display import IFrame\n", + "display(IFrame('http://localhost:8000/classify_output', 700, 350))" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/pcloudcv/connections/local_server.py b/pcloudcv/connections/local_server.py index c4e94a7..414447a 100644 --- a/pcloudcv/connections/local_server.py +++ b/pcloudcv/connections/local_server.py @@ -85,7 +85,8 @@ def classify_output(name=None): imagepath.append(os.path.join(conf.BASE_URL+job.job.jobinfo['url'], k)) scores = output_dict[k] result.append(scores) - print imagepath, result +# print imagepath, result + cherrypy.engine.exit() return template.render(imagepath=imagepath, result = result) @@ -201,4 +202,4 @@ def stop(self): print 'Local Server Stopped' #pass -server = HTTPServer() \ No newline at end of file +server = HTTPServer() diff --git a/pcloudcv/connections/socketConnection.py b/pcloudcv/connections/socketConnection.py index c718868..da20ac9 100644 --- a/pcloudcv/connections/socketConnection.py +++ b/pcloudcv/connections/socketConnection.py @@ -8,7 +8,6 @@ import utility.job as job import traceback import os -import local_server from urlparse import urlparse from os.path import splitext, basename from utility import conf @@ -32,9 +31,9 @@ def __init__(self, executable, imagepath): self._executable = str(executable) self._imagepath = str(imagepath) - redis_thread = self.setupRedis() - redis_thread.setDaemon(True) - redis_thread.start() + self.redis_thread = self.setupRedis() + self.redis_thread.setDaemon(True) + self.redis_thread.start() def setupRedis(self): self._redis_obj = redis.StrictRedis(host='localhost', port=6379, db=0) @@ -51,7 +50,6 @@ def run(self): logging.log('I', 'Exiting Socket Connection Thread') - def connection(self, *args): print 'Connected using websockets' diff --git a/pcloudcv/pcloudcv.py b/pcloudcv/pcloudcv.py index 4b41d03..2b88efd 100644 --- a/pcloudcv/pcloudcv.py +++ b/pcloudcv/pcloudcv.py @@ -10,8 +10,6 @@ sys.path.append(path) import threading -from colorama import init -from colorama import Fore from connections import local_server from utility import accounts, logging from utility.parseArguments import ConfigParser @@ -19,8 +17,6 @@ from connections.uploadData import UploadData from connections.socketConnection import SocketIOConnection -init() - def getfullpath(s): return os.path.join(os.getcw(), s) @@ -79,17 +75,13 @@ def authenticate(self): accounts.authenticate() def run(self): - if self.login_required: self.authenticate() self.sioc.start() time.sleep(4) - self.ud.start() - - - - + self.ud.join() + self.sioc.join() diff --git a/pcloudcv/test.py b/pcloudcv/test.py new file mode 100644 index 0000000..f7696a7 --- /dev/null +++ b/pcloudcv/test.py @@ -0,0 +1,8 @@ +from pcloudcv import PCloudCV +import os +login_required = True +config_dict = {} +path_to_config_file = os.path.join(os.getcwd(), "config.json") +pvc = PCloudCV(path_to_config_file, config_dict, login_required) +pvc.start() + diff --git a/pcloudcv/utility/accounts.py b/pcloudcv/utility/accounts.py index e73c499..1caff85 100644 --- a/pcloudcv/utility/accounts.py +++ b/pcloudcv/utility/accounts.py @@ -140,7 +140,7 @@ def authenticate(): elif 'isValid' in response_json and response_json['isValid'] == 'True': print 'User Authenticated' - print 'Welcome ' + str(response_json['first_name']) + print 'Welcome ' + response_json['first_name'].encode('utf-8') googleAuthentication = True account_obj = Accounts() \ No newline at end of file