<jupyter_start><jupyter_text>Take a picture and run the cloud model on it Prerequisites and cloud credential setup<jupyter_code>import os
import glob

from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.training.models import ImageUrlCreateEntry

from picamera import PiCamera
from time import sleep

ENDPOINT = "https://southcentralus.api.cognitive.microsoft.com"

# Replace with a valid key
training_key = "<enter training key here>"
prediction_key = "<enter prediction key here>"
prediction_resource_id = "<enter prediction resource id here>"

from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient


projectid = "<enter project id here>"
# Now there is a trained endpoint that can be used to make a prediction
predictor = CustomVisionPredictionClient(prediction_key, endpoint=ENDPOINT)
trainer = CustomVisionTrainingClient(training_key,endpoint=ENDPOINT)<jupyter_output><empty_output><jupyter_text>Find a published iteration<jupyter_code>iterations = trainer.get_iterations(projectid);
for iteration in iterations:
    print(iteration.name + "\t" + iteration.id + "\t" + iteration.status, end=' ' )
    if (iteration.publish_name):
        print("published under "+ iteration.publish_name, end=' ')
        publish_iteration_name = iteration.publish_name
    print(" ")
    
print("using "+ publish_iteration_name)<jupyter_output><empty_output><jupyter_text>take a picture and save it in a file<jupyter_code>camera = PiCamera()

camera.resolution =(640,480)


print ("starting camera")
camera.start_preview()
sleep(5)
print ("capture")
camera.capture('/home/pi/camera/image.jpg')
camera.stop_preview()<jupyter_output><empty_output><jupyter_text>send the picture to the cloud for analysis and print the result<jupyter_code>print ("analyzing")
with open('/home/pi/camera/image.jpg',mode="rb") as test_data:
    results = predictor.classify_image(projectid, publish_iteration_name, test_data.read())
    for prediction in results.predictions:
        print ("\t" + prediction.tag_name + ": {0:.2f}%".format(prediction.probability * 100))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10145586897179254, 'fraction_numerical': 0.00545950864422202, 'mean_word_length': 6.454237288135594, 'pattern_counts': {'":': 1, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '26740', 'license': 'MIT', 'n_tokens_mistral': 677, 'n_tokens_neox': 651, 'n_words': 159, 'path': 'camera/RunModelOnCameraPicture.ipynb', 'repo_name': 'chtraver/CognitivePiJupyter', 'size': '2198'}