Skip to main content

Python SDK for the ASpace AI cognitive services

Project description

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

ASpace AI Themes

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:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aspaceai-1.0.13.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

aspaceai-1.0.13-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file aspaceai-1.0.13.tar.gz.

File metadata

  • Download URL: aspaceai-1.0.13.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for aspaceai-1.0.13.tar.gz
Algorithm Hash digest
SHA256 cbe88bb71d8464c3582b617948bfbec3440ffb1d2efaa2ebd73391961ed88382
MD5 c9cb94ad6487ce0cafff55bdd28bc4d9
BLAKE2b-256 fcdfe6128fb70a22c872fb30a7668bd0e9938d07908b5012dd07bf09cbfdbaaf

See more details on using hashes here.

File details

Details for the file aspaceai-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: aspaceai-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for aspaceai-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c0955de4a5bc2759db83b80c8801fc2aa0219a456d21876297aeb98b6704642b
MD5 a27e5fd6bac001d809ce61a1875b87ec
BLAKE2b-256 0cc4b973a7c8e95e3824d75c6e68be069b3be2613a57daf4b7fdad3bff9c63a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page