forked from SAP-archive/SDK-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] methods to response and sentence; [UPD] init, client and entities
- Loading branch information
1 parent
6bcf9ee
commit e104ce4
Showing
10 changed files
with
134 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from recastai import client | ||
import json | ||
import requests | ||
|
||
from .client import Client | ||
from .response import Response | ||
from .sentence import Sentence | ||
from .entity import Entity | ||
from .errors import RecastError | ||
from .utils import Utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,60 @@ | ||
from recastai import utils | ||
from recastai import errors | ||
from recastai import response | ||
# -*- coding: utf-8 -*- | ||
|
||
import requests | ||
|
||
from .response import Response | ||
from .errors import RecastError | ||
from .utils import Utils | ||
|
||
class Client(object): | ||
def __init__(self, token=None): | ||
def __init__(self, token=None, language=None): | ||
self.token = token | ||
self.language = language | ||
|
||
""" | ||
Perform a text request to Recast.AI | ||
""" | ||
def text_request(self, text, **options): | ||
token = options.get('token') or self.token | ||
if token is None: | ||
raise RecastError('Token is missing') | ||
raise RecastError("Token is missing") | ||
|
||
language = options.get('language') or self.language | ||
|
||
response = requests.post("{url}/request".format(url=self.url), | ||
params={'text': text}, | ||
headers={'Authorization': 'Token ' + token} | ||
body = {'text': text} | ||
if language is not None: | ||
body['language'] = language | ||
|
||
response = requests.post(Utils.API_ENDPOINT, | ||
params=body, | ||
headers={'Authorization': "Token " + token} | ||
) | ||
if response.status_code != 200: | ||
if response.status_code != requests.codes.ok: | ||
raise RecastError(response.message) | ||
|
||
return Response(response.body) | ||
print(response.text) | ||
return Response(response.text) | ||
|
||
""" | ||
Perform a text request to Recast.AI | ||
""" | ||
def file_request(self, file, **options): | ||
token = options.get('token') or self.token | ||
if token == None: | ||
raise RecastError('Token is missing') | ||
raise RecastError("Token is missing") | ||
|
||
language = options.get('language') or self.language | ||
|
||
file = open(file, 'rb') if (type(file) is str) else file | ||
body = {'voice': file} | ||
if language is not None: | ||
body['language'] = language | ||
|
||
response = requests.post("{url}/request".format(url=self.url), | ||
files={'voice':file}, | ||
headers={'Authorization': 'Token ' + token} | ||
response = requests.post(Utils.API_ENDPOINT, | ||
files=body, | ||
headers={'Authorization': "Token " + token} | ||
) | ||
if response.status_code != 200: | ||
if response.status_code != requests.codes.ok: | ||
raise RecastError(response.message) | ||
|
||
return Response(response.body) | ||
return Response(response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
class Entity(object): | ||
def __init__(self, name, data): | ||
self.name = name | ||
|
||
for k, v in data.iteritems(): | ||
for k, v in data.items(): | ||
setattr(self, k, v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
class RecastError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
class Utils(object): | ||
# Versioning | ||
"""Versioning""" | ||
MAJOR = '1' | ||
MINOR = '0' | ||
MICRO = '2' | ||
MICRO = '0' | ||
VERSION = "{0}.{1}.{2}".format(MAJOR, MINOR, MICRO) | ||
|
||
# Endpoints | ||
"""Endpoints""" | ||
API_ENDPOINT = 'https://api.recast.ai/v1/request' | ||
WS_ENDPOINT = 'wss://api.recast.ai/v1/request' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from distutils.core import setup | ||
from setuptools import setup | ||
|
||
setup( | ||
name="recastai", | ||
|