Skip to content
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
210 changes: 113 additions & 97 deletions pcloudcv/Classification Visualization.ipynb
Original file line number Diff line number Diff line change
@@ -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('<iframe src=http://localhost:8000/classify_output width=700 height=350></iframe>')\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))"
]
}
]
}
],
"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
}
5 changes: 3 additions & 2 deletions pcloudcv/connections/local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -201,4 +202,4 @@ def stop(self):
print 'Local Server Stopped'

#pass
server = HTTPServer()
server = HTTPServer()
8 changes: 3 additions & 5 deletions pcloudcv/connections/socketConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -51,7 +50,6 @@ def run(self):

logging.log('I', 'Exiting Socket Connection Thread')


def connection(self, *args):
print 'Connected using websockets'

Expand Down
12 changes: 2 additions & 10 deletions pcloudcv/pcloudcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
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
import utility.job as job
from connections.uploadData import UploadData
from connections.socketConnection import SocketIOConnection

init()

def getfullpath(s):
return os.path.join(os.getcw(), s)

Expand Down Expand Up @@ -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()

8 changes: 8 additions & 0 deletions pcloudcv/test.py
Original file line number Diff line number Diff line change
@@ -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()

2 changes: 1 addition & 1 deletion pcloudcv/utility/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()