Git Product home page Git Product logo

prediction-try-java-python's Introduction

prediction-try-java-python

Sample application illustrating use of the Google Prediction API within the Google App Engine environmentTry Prediction (v1.0)

This project provides a complete application illustrating use of the Google Prediction API within the Google App Engine environment. Sample code is provided for both the Java and Python App Engine runtimes, along with resources for CSS, Javascript, images and config data files, all of which are shared across the two runtime environments.

The application presents a simple interactive user experience: select a prediction model, enter a corresponding set of input text and submit your prediction request. For classification models, a graphical response is provided showing the confidence level for each category in the selected model. For regression models, a numerical result is presented.

The set of models supported and the corresponding input fields are entirely dynamic and controlled by a runtime text file (rc/models.json). You can freely add, change or remove models without changing any source code.

Web services in this domain typically provide access to a prediction model via a common set of shared security credentials. In this model, there is no need to force end users to perform the OAuth token granting sequence - authorization of end users is entirely up to the discretion of the application provider. This shared-server authorization model is one of the key elements being illustrated in this sample application.

You can try a live instance of this application at http://try-prediction.appspot.com.

Prerequisites

Before using this project, you should familiarize yourself with the Google Prediction API Developer's Guide and experiment with the "Hello Prediction!" sample exercise. You should have at least one trained model of your own to use with the Try Prediction app.

Dependencies for the Python version:

  • Python 2.5 or later
  • Google App Engine
  • Google Python API Client
  • Command line flags modules for Python
  • HTTP Client Library for Python
  • Google OAuth 2.0 Client Library for Python
  • URI Templates for Python

Dependencies for the Java version:

  • Java 5 (or higher) standard (SE) and enterprise (EE)
  • Google App Engine
  • Maven
  • Maven Plugin for App Engine

Getting Started

  1. Clone this repo into a new directory.

  2. Customize the following files:

- In shared/rc/client_secrets.json, replace the placeholder strings with your actual client id and 
  client secret from the Google APIs console.

- In shared/rc/models.json, enter information about the model(s) you would like to use, following 
  the format shown for the two sample models.

- Java only: edit the file gae-java/src/main/java/com/google/tryPredictionJava/web/IndexServlet.java 
  to specify your redirect URI, which should be your app's base URI + 
  /auth_return, e.g. http://your-app-name.appspot.com/auth_return.

- Add your redirect URI (defined in previous step) to the list of valid 
  redirect URIs in the "API Access" tab of the APIs Console. If you miss 
  this step, you'll get a 'redirect_uri_mismatch' error during initial 
  authorization of the shared server credentials.
  1. Build and deploy your app:
- For Python:
  - Modify the "application:" line in your app.yaml file to
     reflect your chosen app name and use the Google App Engine tools to
     deploy your app.
  - Install google-api-python-client library to your project vendor dir via pip:
     `pip install -t vendor -r requirements.txt`
     Note: this is only required for dev. On production this is done upon deployment

- For Java: modify the contents of the "application" XML element in 
  your gae-java/src/main/webapp/WEB-INF/appengine-web.xml file to 
  reflect your chosen app name and use the Maven plugin for Google 
  App Engine to deploy your app (you need to run "mvn gae:unpack" 
  once and then you can subsequently deploy your app repeatedly 
  with "mvn gae:deploy").
  1. The first time you access your app, it will step you through the login and OAuth 2.0 sequence, however, all access thereafter, by you or anyone else, will reuse your initially established security credentials. If you ever wish to change or re-establish the shared server credentials, simply visit your service's URI with the "/reset" suffix (note that the reset service can only be invoked by the application administrator).

Try Prediction is brought to you by the Google Developer Relations team.

prediction-try-java-python's People

Contributors

jimmykane avatar mco-gh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prediction-try-java-python's Issues

Upgrade to hosted models

Since the project does not offer the training models it is hard for someone to try and use the project locally.
I have managed to use it with hosted models, and upgrading all functions to v1.6 of the prediction API and this way I can use and try the prediction API.

Current version is deprecated, request for work around

Dear Marc,

Thank you for uploading the try-prediction sample.

We've downloaded the code and encountered two incompatibility issues:

  1. AuthReturnServlet.java - AccessTokenResponse is deprecated.
    We'd like to replace the following line:
    AccessTokenResponse tokens = new GoogleAuthorizationCodeGrant(transport, jsonFactory, clientId, clientSecret, code, IndexServlet.redirectUri).execute();
  2. Predict Servlet.java - GoogleAccessProtectedResource is deprecated.
    We'd like to replace the folioing line:
    GoogleAccessProtectedResource requestInitializer = new GoogleAccessProtectedResource(tokens.getAccessToken(), httpTransport, jsonFactory, clientId, clientSecret, tokens.getRefreshToken());

We'd appreciate it if you could direct us to alternatives which work with the latest API versions.

Thanks,
Rydell

The POM for com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta is missing

Hello,

I am getting this error from Maven....

mvn -e gae:unpack
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building try-prediction-java 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-gae-plugin:0.9.0:unpack (default-cli) > initialize @ gae-java >>>
[INFO]
[INFO] <<< maven-gae-plugin:0.9.0:unpack (default-cli) < initialize @ gae-java <<<
[WARNING] The POM for com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.982 s
[INFO] Finished at: 2016-01-05T14:45:59-06:00
[INFO] Final Memory: 7M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project gae-java: Could not resolve dependencies for project com.google.tryPredictionJava:gae-java:war:1.0-SNAPSHOT: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project gae-java: Could not resolve dependencies for project com.google.tryPredictionJava:gae-java:war:1.0-SNAPSHOT: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:221)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)
at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:245)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:199)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project com.google.tryPredictionJava:gae-java:war:1.0-SNAPSHOT: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:211)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:195)
... 23 more
Caused by: org.eclipse.aether.resolution.DependencyResolutionException: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:384)
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:205)
... 24 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:367)
... 25 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find com.google.apis:google-api-services-prediction:jar:v1.4-1.3.0-beta in http://mavenrepo.google-api-java-client.googlecode.com/hg was cached in the local repository, resolution will not be reattempted until the update interval of google-api-services has elapsed or updates are forced
at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:231)
at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
... 27 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.