Skip to content

Commit 4dba46e

Browse files
committed
Examples
1 parent 342063e commit 4dba46e

20 files changed

+495
-79
lines changed

dist/firstlanguage_python-2.4.tar.gz

40.9 KB
Binary file not shown.

example_Stemmer.py

-44
This file was deleted.

examples/Advanced/example_Classify.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#Create the input string and prep it to pass it to the API
11+
reqbody='{"input":{"text":"Smiling makes everyone happy","lang":"en", "labels":["positive","negative"]} }'
12+
body = jsonpickle.decode(reqbody)
13+
14+
#Initialize the corresponding controller Basic or Advacned
15+
adv_api_controller = client.advanced_api
16+
17+
#Call the corresponding API
18+
result = adv_api_controller.get_classification(body)
19+
20+
print("Labels: ",result.labels)
21+
print("Scores: ",result.scores)
22+
23+
24+
#From URL:
25+
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
26+
body = jsonpickle.decode(reqbody)
27+
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")
28+
29+
body["input"]["lang"] = "en"
30+
body["input"]["url"] = decoded_url
31+
body["input"]["contentType"] = "pdf"
32+
body["input"]["labels"] = ["positive","negative"]
33+
34+
#Initialize the corresponding controller Basic or Advacned
35+
adv_api_controller = client.advanced_api
36+
37+
#Call the corresponding API
38+
result = adv_api_controller.get_classification(body)
39+
40+
print("Labels: ",result.labels)
41+
print("Scores: ",result.scores)
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#From URL:
11+
reqbody = '{"input":{"url": ""} }'
12+
body = jsonpickle.decode(reqbody)
13+
decoded_url = bytes("https://i.redd.it/v1fvin01ynv51.jpg", "utf-8").decode("unicode_escape")
14+
15+
16+
body["input"]["url"] = decoded_url
17+
18+
19+
#Initialize the corresponding controller Basic or Advacned
20+
adv_api_controller = client.advanced_api
21+
22+
#Call the corresponding API
23+
result = adv_api_controller.get_image_caption(body)
24+
25+
print("Caption: ",result.generated_caption)

examples/Advanced/example_NER.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#Create the input string and prep it to pass it to the API
11+
reqbody='{"input":{"text":"FirstLanguage is a NLP company","lang":"en"} }'
12+
body = jsonpickle.decode(reqbody)
13+
14+
#Initialize the corresponding controller Basic or Advacned
15+
adv_api_controller = client.advanced_api
16+
17+
#Call the corresponding API
18+
res = adv_api_controller.get_ner(body)
19+
20+
for result in res:
21+
print("Word: ",result.word)
22+
print("Start index: ",result.start)
23+
print("End index: ",result.end)
24+
print("Entity Group: ",result.entity_group)
25+
26+
#From URL:
27+
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
28+
body = jsonpickle.decode(reqbody)
29+
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")
30+
31+
body["input"]["lang"] = "en"
32+
body["input"]["url"] = decoded_url
33+
body["input"]["contentType"] = "pdf"
34+
35+
36+
#Initialize the corresponding controller Basic or Advacned
37+
adv_api_controller = client.advanced_api
38+
39+
#Call the corresponding API
40+
res = adv_api_controller.get_ner(body)
41+
42+
for result in res:
43+
print("Word: ",result.word)
44+
print("Start index: ",result.start)
45+
print("End index: ",result.end)
46+
print("Entity Group: ",result.entity_group)

examples/Advanced/example_QA.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#Create the input string and prep it to pass it to the API
11+
reqbody='{"input":{"context":"உப்பு, புளி, மிளகாய் மூன்றும் எப்போதும் ஒன்றாகவே இருக்கும். ஒருநாள், “குழம்பிற்கு யார் முக்கியம்? நீயா! நானா!” என்று சண்டை போட்டன. மூன்று பேரும் தனிதனியாகச் சென்று குழம்பில் சேரலாம் என்று முடிவு செய்தன. முதல் நாள், உப்பு மட்டும் குழம்பில் சேர்ந்து கொண்டது. “ஆ! ஒரே உப்பு! வாயில் வைக்க முடியவில்லை!” என்று எல்லோரும் கத்தினார்கள்","lang":"ta","question": "எவை மூன்றும் எப்போதும் ஒன்றாகவே இருக்கும்?"} }'
12+
body = jsonpickle.decode(reqbody)
13+
14+
#Initialize the corresponding controller Basic or Advacned
15+
adv_api_controller = client.advanced_api
16+
17+
#Call the corresponding API
18+
result = adv_api_controller.get_qa(body)
19+
20+
print("Score: ",result.score)
21+
print("Start index of the answer in the context: ",result.start)
22+
print("End index of the answer in the context: ",result.end)
23+
print("Answer: ",result.answer)
24+
25+
26+
#From URL:
27+
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
28+
body = jsonpickle.decode(reqbody)
29+
decoded_url = bytes("https://docs.google.com/document/d/1p8ER__mGPlu59zCrqH1PxNNao92qBsq-/export?format=docx", "utf-8").decode("unicode_escape")
30+
31+
body["input"]["lang"] = "en"
32+
body["input"]["url"] = decoded_url
33+
body["input"]["contentType"] = "docx"
34+
body["input"]["question"] = ["What is FirstLanguage's motto?"]
35+
36+
#Initialize the corresponding controller Basic or Advacned
37+
adv_api_controller = client.advanced_api
38+
39+
#Call the corresponding API
40+
result = adv_api_controller.get_qa(body)
41+
42+
print("Score: ",result.score)
43+
print("Start index of the answer in the context: ",result.start)
44+
print("End index of the answer in the context: ",result.end)
45+
print("Answer: ",result.answer)

examples/Advanced/example_Summary.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
# Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
# Create the input string and prep it to pass it to the API
11+
reqbody = '{"input":{"text":"We at FirstLanguage Technologies build state-of-the-art NLP APIsolutions for your\
12+
business at lowest price in the market. FirstLanguageTechnologies was founded in the year 2021 with a mission\
13+
to spread NLP technology across the world. NLP for the masses is our motto. We provide API services which\
14+
are simple to use, easy to integrate and can be understood very easily by anyone.\
15+
FirstLanguage provides basics APIssuch as, stemmer, POS Tagger, Morphological Analyzer.\
16+
and Lemmatizer. The advanced APIs provided by FirstLanguage are,Question Answering,\
17+
Table Question Answering, Summarization and Machine Translation. \
18+
All these APIs are built using state-of-the art deeplearning models fine tuned by us \
19+
and works for 100 plus languages.","lang":"en"} }'
20+
body = jsonpickle.decode(reqbody)
21+
22+
# Initialize the corresponding controller Basic or Advacned
23+
adv_api_controller = client.advanced_api
24+
25+
# Call the corresponding API
26+
res = adv_api_controller.get_summary(body)
27+
28+
print(res.summary)
29+
30+
# From URL:
31+
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
32+
body = jsonpickle.decode(reqbody)
33+
decoded_url = bytes("https://docs.google.com/document/d/1p8ER__mGPlu59zCrqH1PxNNao92qBsq-/export?format=docx",
34+
"utf-8").decode("unicode_escape")
35+
36+
body["input"]["lang"] = "en"
37+
body["input"]["url"] = decoded_url
38+
body["input"]["contentType"] = "docx"
39+
40+
41+
# Initialize the corresponding controller Basic or Advacned
42+
adv_api_controller = client.advanced_api
43+
44+
# Call the corresponding API
45+
res = adv_api_controller.get_summary(body)
46+
47+
print(res.summary)

examples/Advanced/example_TableQA.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#Create the input string and prep it to pass it to the API
11+
reqbody='{"input":{"flattable":{"Cities":["Paris, France","London, England","Lyon, France"],"Inhabitants":["2.161","8.982","0.513"]},"sendBackRows":false,"questions":["How many inhabitants in France","How Many inhabitants in England"]} }'
12+
body = jsonpickle.decode(reqbody)
13+
14+
#Initialize the corresponding controller Basic or Advacned
15+
adv_api_controller = client.advanced_api
16+
17+
#Call the corresponding API
18+
result = adv_api_controller.get_table_qa(body)
19+
20+
for item in result:
21+
print("Query: ",item.query)
22+
print("Answers: ",item.answer)
23+
24+
25+
26+
27+
#From URL:
28+
reqbody = '{"input":{"questions":"","url": "","sendBackRows":"false"} }'
29+
body = jsonpickle.decode(reqbody)
30+
decoded_url = bytes("https://drive.google.com/uc?id=1IpBFNs4FlRRbDzL_XPtmGHou_Rvc5Mvq", "utf-8").decode("unicode_escape")
31+
32+
33+
body["input"]["url"] = decoded_url
34+
body["input"]["questions"] = ["How many inhabitants in France"]
35+
36+
#Initialize the corresponding controller Basic or Advacned
37+
adv_api_controller = client.advanced_api
38+
39+
#Call the corresponding API
40+
result = adv_api_controller.get_table_qa(body)
41+
42+
for item in result:
43+
print("Query: ",item.query)
44+
print("Answers: ",item.answer)
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
import base64
5+
import io
6+
7+
# Init client with apiKey. Environment will always be set to PRODUCTION for now.
8+
client = Client(
9+
apikey='<Your_API_Key>',
10+
environment=Environment.PRODUCTION,)
11+
12+
# Create the input string and prep it to pass it to the API
13+
reqbody = '{"input":{"text":"Today is a good day","lang":"ta"} }'
14+
15+
body = jsonpickle.decode(reqbody)
16+
17+
# Initialize the corresponding controller Basic or Advacned
18+
adv_api_controller = client.advanced_api
19+
20+
# Call the corresponding API
21+
res = adv_api_controller.get_translate(body)
22+
23+
print(res.generated_text)
24+
25+
# From URL:
26+
#Prepare input
27+
reqbody='{"input":{"lang":"ja","url": "https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "contentType":"pdf","preserveFormat":"true"} }'
28+
body = jsonpickle.decode(reqbody)
29+
30+
# Initialize the corresponding controller Basic or Advacned
31+
advanced_api_controller = client.advanced_api
32+
33+
34+
# Call the corresponding API
35+
result = advanced_api_controller.get_translate(body)
36+
37+
if(body['input']['contentType'] == 'docx'):
38+
with open('output.docx', 'w') as f:
39+
f.write(result.text)
40+
f.close()
41+
42+
if(body['input']['contentType'] == 'pdf'):
43+
with open('output.pdf', 'wb') as f:
44+
f.write(result.text)
45+
f.close()
46+
print("File saved to disk")
47+

examples/Basic/example_Lemma.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
#Init client with apiKey. Environment will always be set to PRODUCTION for now.
6+
client = Client(
7+
apikey='<Your_API_Key>',
8+
environment=Environment.PRODUCTION,)
9+
10+
#Create the input string and prep it to pass it to the API
11+
reqbody='{"input":{"text":"Smiling makes everyone happy","lang":"en"} }'
12+
body = jsonpickle.decode(reqbody)
13+
14+
#Initialize the corresponding controller Basic or Advacned
15+
basic_api_controller = client.basic_api
16+
17+
#Call the corresponding API
18+
result = basic_api_controller.get_lemma(body)
19+
20+
#Parse the result
21+
for res in result:
22+
print("Original Text passed: "+res.original_text)
23+
print("Lemmatized result: "+res.lemmatized)
24+
25+
26+
#From URL:
27+
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
28+
body = jsonpickle.decode(reqbody)
29+
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")
30+
31+
body["input"]["lang"] = "en"
32+
body["input"]["url"] = decoded_url
33+
body["input"]["contentType"] = "pdf"
34+
35+
#Initialize the corresponding controller Basic or Advacned
36+
basic_api_controller = client.basic_api
37+
38+
#Call the corresponding API
39+
result = basic_api_controller.get_lemma(body)
40+
41+
#Parse the result
42+
for res in result:
43+
print("Original Text passed: "+res.original_text)
44+
print("Lemmatized result: "+res.lemmatized)

0 commit comments

Comments
 (0)