forked from LiKev12/CSE544T-Project-TextBugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
official_classifiers.py
41 lines (27 loc) · 890 Bytes
/
official_classifiers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
import requests
import json
def c_google():
# Instantiates a client
client = language.LanguageServiceClient()
# The text to analyze
text = u'I hate being late.'
document = types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
# Detects the sentiment of the text
sentiment = client.analyze_sentiment(document=document).document_sentiment
print('Text: {}'.format(text))
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))
def c_ibm():
url = 'http://max-text-sentiment-classifier.max.us-south.containers.appdomain.cloud/model/predict'
myobj = {
"text": [
"Happy"
]
}
x = requests.post(url, data = json.dumps(myobj))
print(x)
c_ibm()