Package: aspaceai
ASpace AI API: Python SDK & SampleThis repo contains the Python SDK for the ASpace AI cognitive services, an offering withinASpace AI Cognitive ServicesLearn about EY ASpace AI PlatformGetting startedInstall the module usingpip:pipinstallaspaceaiUse it:'''-------------------------------------------------- OCR ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image_url='https://i.ibb.co/3RHzMqB/eurotext.png'result=aspaceai.vision.ocr(image=image_url,image_format='url',language='eng')operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':print(json.loads(result)['result'])else:print(json.loads(result)['message'])'''-------------------------------------------------- PART OF SPEECH ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="The quick brown fox jumps over the lazy dog"result=aspaceai.nlp.part_of_speech(text)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':print(json.loads(result)['result'])else:print(json.loads(result)['message'])'''-------------------------------------------------- NAMED ENTITY RECOGNITION ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices"result=aspaceai.nlp.named_entity_recognition(text)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':print(json.loads(result)['result'])else:print(json.loads(result)['message'])'''-------------------------------------------------- DEPENDENCY PARSER------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices"result=aspaceai.nlp.dependency_parser(text)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':print(json.loads(result)['result'])else:print(json.loads(result)['message'])'''-------------------------------------------------- TAGS EXTRACTION------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices"result=aspaceai.nlp.tags_extraction(text)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':print(json.loads(result)['result'])else:print(json.loads(result)['message'])'''-------------------------------------------------- FACE DETECTION ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image="https://www.thestatesman.com/wp-content/uploads/2017/08/1493458748-beauty-face-517.jpg"image_format="url"result=aspaceai.vision.face_detection_image(image,image_format)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':base64_image_string=json.loads(result)['result']['image']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- EYE DETECTION ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image="https://www.thestatesman.com/wp-content/uploads/2017/08/1493458748-beauty-face-517.jpg"image_format="url"result=aspaceai.vision.eye_detection(image,image_format)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':base64_image_string=json.loads(result)['result']['image']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- SMILE DETECTION ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image="https://st.depositphotos.com/1008939/3024/i/950/depositphotos_30248143-stock-photo-beautiful-woman-smiling.jpg"image_format="url"result=aspaceai.vision.smile_detection(image,image_format)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':base64_image_string=json.loads(result)['result']['image']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- OBJECT DETECTION ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image="https://i.pinimg.com/564x/0d/b6/10/0db610089c3e8bfef6c33c3059f70903.jpg"image_format="url"result=aspaceai.vision.object_detection(image,image_format)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':objects=json.loads(result)['result']['objects']print(objects)base64_image_string=json.loads(result)['result']['image']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- IMAGE CLASSIFICATION ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.image="https://i.pinimg.com/564x/0d/b6/10/0db610089c3e8bfef6c33c3059f70903.jpg"image_format="url"result=aspaceai.vision.image_classification(image,image_format)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':objects_identified=json.loads(result)['result']print(objects_identified)else:print(json.loads(result)['message'])'''-------------------------------------------------- SENTIMENT ANALYSIS ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="Hello ASpace World, its a great day !!!"result=aspaceai.sense.sentiment_analysis(text)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':objects_identified=json.loads(result)['result']print(objects_identified)else:print(json.loads(result)['message'])'''-------------------------------------------------- TRANSLATE ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="Hello ASpace World, its a great day !!!"result=aspaceai.nlp.translate(text,"en","hi")operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':objects_identified=json.loads(result)['result']print(objects_identified)else:print(json.loads(result)['message'])'''-------------------------------------------------- QR CREATOR ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text_to_encode="Hello ASpace World !!!"result=aspaceai.vision.qr_creator(text_to_encode)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':base64_image_string=json.loads(result)['result']['QRCodeImage']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- BARCODE CREATOR ------------------------------------------------------'''importaspaceaiimportjsonimportcv2importnumpyasnpimportbase64aspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text_to_encode="Hello ASpace World !!!"result=aspaceai.vision.barcode_creator(text_to_encode)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':base64_image_string=json.loads(result)['result']['BarCodeImage(base64)']jpg_original=base64.b64decode(base64_image_string)jpg_as_np=np.frombuffer(jpg_original,dtype=np.uint8)img=cv2.imdecode(jpg_as_np,flags=1)cv2.imshow("Output From ASpaceAI",img)cv2.waitKey(0)cv2.destroyAllWindows();else:print(json.loads(result)['message'])'''-------------------------------------------------- QR CODE READER ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.qr_code_image_path=r"C:\Users\<>\Downloads\qr.jpg"result=aspaceai.vision.qr_reader(qr_code_image_path)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':data=json.loads(result)['result']['data']print(data)else:print(json.loads(result)['message'])'''-------------------------------------------------- BARCODE READER ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.barcode_image_path=r"C:\Users\<>\Downloads\bar.jpg"result=aspaceai.vision.barcode_reader(barcode_image_path)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':data=json.loads(result)['result']['data']print(data)else:print(json.loads(result)['message'])'''-------------------------------------------------- SPEECH TO TEXT ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.wav_audio_file_path=r"C:\Users\<>\Downloads\audio_sample.wav"audio_language="en-IN"result=aspaceai.speech.speech_to_text(wav_audio_file_path,audio_language)operation_status=json.loads(result)['status']ifoperation_status.lower()=='success':data=json.loads(result)['result']['text']print(data)else:print(json.loads(result)['message'])'''-------------------------------------------------- TEXT TO SPEECH  ------------------------------------------------------'''importaspaceaiimportjsonaspaceai.ASPACE_API_URL='< ASpace AI API endpoint URL >'# Replace with your aspace endpoint URLaspaceai.ASPACE_API_KEY='< ASpace AI API KEY >'# Replace with a valid Subscription Key here.text="Hello ASpace World !!!"text_lang="en-US-AriaNeural"operation_status,result=aspaceai.speech.text_to_speech(text,text_lang)ifoperation_status.lower()=='success':withopen('text_to_speech.wav','wb')asf:f.write(result.content)# Retrieve HTTP meta-dataprint(result.status_code)print(result.headers['content-type'])print(result.encoding)else:print(result)Installing from the source codepythonsetup.pyinstallContributingWe welcome contributions. Feel free to file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on ourContribution Rules & Guidelines.You can reach out to us anytime with questions and suggestions using our communities below:Support questions:StackOverflowUpdatesASpace.ai Platform Release NotesLicenseAll ASpace Cognitive Services SDKs and samples are licensed with the MIT License. For more details, seeLICENSE.Developer Code of ConductDevelopers using Cognitive Services, including this sample, are expected to follow the “Developer Code of Conduct for ASpace AI”, found athttps://www.ey.com/en_in/consulting/accelerating-digital-transformation-with-ai.