Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
Last active January 21, 2018 16:02
Show Gist options
  • Save qzchenwl/2c95b7e38ef852b56e0e751f9acb8f43 to your computer and use it in GitHub Desktop.
Save qzchenwl/2c95b7e38ef852b56e0e751f9acb8f43 to your computer and use it in GitHub Desktop.
$ gcloud auth application-default login && cat ~/.config/gcloud/application_default_credentials.json
asn1crypto==0.23.0
bleach==1.5.0
cachetools==2.0.1
certifi==2017.11.5
cffi==1.11.2
chardet==3.0.4
click==6.7
conda==4.3.31
cryptography==2.1.4
decorator==4.2.1
entrypoints==0.2.3
enum34==1.1.6
gcloud==0.18.3
google-api-core==0.1.4
google-auth==1.3.0
google-cloud-core==0.28.0
google-cloud-storage==1.7.0
google-cloud-vision==0.29.0
google-resumable-media==0.3.1
googleapis-common-protos==1.5.3
grpcio==1.8.4
html5lib==0.9999999
httplib2==0.10.3
idna==2.6
ipykernel==4.8.0
ipython==6.2.1
ipython-genutils==0.2.0
ipywidgets==7.1.0
itsdangerous==0.24
jedi==0.11.1
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.1
jupyter-console==5.2.0
jupyter-core==4.4.0
Markdown==2.6.10
MarkupSafe==1.0
mistune==0.8.3
nbconvert==5.3.1
nbformat==4.4.0
notebook==5.3.1
numpy==1.13.3
oauth2client==4.1.2
pandocfilters==1.4.2
parso==0.1.1
pexpect==4.3.1
pickleshare==0.7.4
Pillow==5.0.0
prompt-toolkit==1.0.15
protobuf==3.5.1
ptyprocess==0.5.2
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycosat==0.6.3
pycparser==2.18
Pygments==2.2.0
pyOpenSSL==17.5.0
PySocks==1.6.7
python-dateutil==2.6.1
pytz==2017.3
pyzmq==16.0.3
qtconsole==4.3.1
requests==2.18.4
rsa==3.4.2
ruamel-yaml==0.11.14
Send2Trash==1.4.2
simplegeneric==0.8.1
six==1.11.0
tensorflow==1.4.0
tensorflow-tensorboard==0.4.0rc3
terminado==0.8.1
testpath==0.3.1
tornado==4.5.3
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
web.py==0.40.dev0
Werkzeug==0.13
widgetsnbextension==3.1.0
import json
import io
import os
import web
from io import BytesIO
from PIL import Image
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
# Instantiates a client
client = vision.ImageAnnotatorClient()
urls = ('/', 'Index')
class Index:
def GET(self):
return """
<html><head><title>图片标签</title><link href='//s.electerious.com/formbase/dist/formbase.min.css' rel="stylesheet" type="text/css"/></head><body>
<form method="POST" enctype="multipart/form-data" action="">
<label class="label" for="myfile">选择图片</label>
<input class="input" id="myfile" name="myfile" type="file">
<input class="input" type="submit">
</form>
</body></html>"""
def POST(self):
x = web.input(myfile={})
img = Image.open(x['myfile'].file)
# Reduce image size
size, min_size = img.size, 1000.0
ratio = min(min_size/size[0], min_size/size[1])
if ratio < 1:
img = img.resize((int(size[0]*ratio), int(size[1]*ratio)))
bytesio = BytesIO()
img.save(bytesio, img.format or 'PNG')
image = types.Image(content=bytesio.getvalue())
# Performs label detection on the image file
response = client.label_detection(image=image)
return response
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment