ASpace AI API: Python SDK & Sample
This repo contains the Python SDK for the ASpace AI cognitive services, an offering within ASpace AI Cognitive Services
Getting started
Install the module using pip:
pip install aspaceai
Use it:
'''-------------------------------------------------- OCR ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
print (json.loads(result)['result'])
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- PART OF SPEECH ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
print (json.loads(result)['result'])
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- NAMED ENTITY RECOGNITION ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
print (json.loads(result)['result'])
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- DEPENDENCY PARSER------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
print (json.loads(result)['result'])
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- TAGS EXTRACTION------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
print (json.loads(result)['result'])
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- FACE DETECTION ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
objects_identified = json.loads(result)['result']
print(objects_identified)
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- SENTIMENT ANALYSIS ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
objects_identified = json.loads(result)['result']
print(objects_identified)
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- TRANSLATE ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
objects_identified = json.loads(result)['result']
print(objects_identified)
else:
print (json.loads(result)['message'])
'''-------------------------------------------------- QR CREATOR ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
import cv2
import numpy as np
import base64
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_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 ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
data = json.loads(result)['result']['data']
print(data)
else:
print(json.loads(result)['message'])
'''-------------------------------------------------- BARCODE READER ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
data = json.loads(result)['result']['data']
print(data)
else:
print(json.loads(result)['message'])
'''-------------------------------------------------- SPEECH TO TEXT ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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']
if operation_status.lower() == 'success':
data = json.loads(result)['result']['text']
print(data)
else:
print(json.loads(result)['message'])
'''-------------------------------------------------- TEXT TO SPEECH ------------------------------------------------------'''
import aspaceai
import json
aspaceai.ASPACE_API_URL = '< ASpace AI API endpoint URL >' # Replace with your aspace endpoint URL
aspaceai.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)
if operation_status.lower() == 'success':
with open('text_to_speech.wav', 'wb') as f:
f.write(result.content)
# Retrieve HTTP meta-data
print(result.status_code)
print(result.headers['content-type'])
print(result.encoding)
else:
print(result)
Installing from the source code
python setup.py install
Contributing
We 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 our Contribution Rules & Guidelines.
You can reach out to us anytime with questions and suggestions using our communities below:
- Support questions: StackOverflow
Updates
License
All ASpace Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see LICENSE.
Developer Code of Conduct
Developers using Cognitive Services, including this sample, are expected to follow the “Developer Code of Conduct for ASpace AI”, found at https://www.ey.com/en_in/consulting/accelerating-digital-transformation-with-ai.
Metadata
Release files for aspaceai 1.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aspaceai-1.0.13.tar.gz | 12.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aspaceai-1.0.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.5 kB
Release files / aspaceai-1.0.13.tar.gz
| Download URL | aspaceai-1.0.13.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbe88bb71d8464c3582b617948bfbec3440ffb1d2efaa2ebd73391961ed88382
|
|
BLAKE2b-256 checksum How to use checksums |
fcdfe6128fb70a22c872fb30a7668bd0e9938d07908b5012dd07bf09cbfdbaaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.24.0 CPython/3.7.9
|
Release files / aspaceai-1.0.13-py3-none-any.whl
| Download URL | aspaceai-1.0.13-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0955de4a5bc2759db83b80c8801fc2aa0219a456d21876297aeb98b6704642b
|
|
BLAKE2b-256 checksum How to use checksums |
0cc4b973a7c8e95e3824d75c6e68be069b3be2613a57daf4b7fdad3bff9c63a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.24.0 CPython/3.7.9
|
Security for aspaceai 1.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.