Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FirstLanguage/firstlanguage_python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4
Choose a base ref
...
head repository: FirstLanguage/firstlanguage_python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: gh-pages
Choose a head ref
  • 2 commits
  • 20 files changed
  • 1 contributor

Commits on Mar 13, 2022

  1. Examples

    subalalithafl committed Mar 13, 2022
    Copy the full SHA
    4dba46e View commit details

Commits on Apr 2, 2022

  1. Remove enum34

    subalalithafl committed Apr 2, 2022
    Copy the full SHA
    1db77bb View commit details
Binary file added dist/firstlanguage_python-2.4.tar.gz
Binary file not shown.
44 changes: 0 additions & 44 deletions example_Stemmer.py

This file was deleted.

41 changes: 41 additions & 0 deletions examples/Advanced/example_Classify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#Create the input string and prep it to pass it to the API
reqbody='{"input":{"text":"Smiling makes everyone happy","lang":"en", "labels":["positive","negative"]} }'
body = jsonpickle.decode(reqbody)

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_classification(body)

print("Labels: ",result.labels)
print("Scores: ",result.scores)


#From URL:
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")

body["input"]["lang"] = "en"
body["input"]["url"] = decoded_url
body["input"]["contentType"] = "pdf"
body["input"]["labels"] = ["positive","negative"]

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_classification(body)

print("Labels: ",result.labels)
print("Scores: ",result.scores)
25 changes: 25 additions & 0 deletions examples/Advanced/example_ImageCaption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#From URL:
reqbody = '{"input":{"url": ""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://i.redd.it/v1fvin01ynv51.jpg", "utf-8").decode("unicode_escape")


body["input"]["url"] = decoded_url


#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_image_caption(body)

print("Caption: ",result.generated_caption)
46 changes: 46 additions & 0 deletions examples/Advanced/example_NER.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#Create the input string and prep it to pass it to the API
reqbody='{"input":{"text":"FirstLanguage is a NLP company","lang":"en"} }'
body = jsonpickle.decode(reqbody)

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
res = adv_api_controller.get_ner(body)

for result in res:
print("Word: ",result.word)
print("Start index: ",result.start)
print("End index: ",result.end)
print("Entity Group: ",result.entity_group)

#From URL:
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")

body["input"]["lang"] = "en"
body["input"]["url"] = decoded_url
body["input"]["contentType"] = "pdf"


#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
res = adv_api_controller.get_ner(body)

for result in res:
print("Word: ",result.word)
print("Start index: ",result.start)
print("End index: ",result.end)
print("Entity Group: ",result.entity_group)
45 changes: 45 additions & 0 deletions examples/Advanced/example_QA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#Create the input string and prep it to pass it to the API
reqbody='{"input":{"context":"உப்பு, புளி, மிளகாய் மூன்றும் எப்போதும் ஒன்றாகவே இருக்கும். ஒருநாள், “குழம்பிற்கு யார் முக்கியம்? நீயா! நானா!” என்று சண்டை போட்டன. மூன்று பேரும் தனிதனியாகச் சென்று குழம்பில் சேரலாம் என்று முடிவு செய்தன. முதல் நாள், உப்பு மட்டும் குழம்பில் சேர்ந்து கொண்டது. “ஆ! ஒரே உப்பு! வாயில் வைக்க முடியவில்லை!” என்று எல்லோரும் கத்தினார்கள்","lang":"ta","question": "எவை மூன்றும் எப்போதும் ஒன்றாகவே இருக்கும்?"} }'
body = jsonpickle.decode(reqbody)

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_qa(body)

print("Score: ",result.score)
print("Start index of the answer in the context: ",result.start)
print("End index of the answer in the context: ",result.end)
print("Answer: ",result.answer)


#From URL:
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://docs.google.com/document/d/1p8ER__mGPlu59zCrqH1PxNNao92qBsq-/export?format=docx", "utf-8").decode("unicode_escape")

body["input"]["lang"] = "en"
body["input"]["url"] = decoded_url
body["input"]["contentType"] = "docx"
body["input"]["question"] = ["What is FirstLanguage's motto?"]

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_qa(body)

print("Score: ",result.score)
print("Start index of the answer in the context: ",result.start)
print("End index of the answer in the context: ",result.end)
print("Answer: ",result.answer)
47 changes: 47 additions & 0 deletions examples/Advanced/example_Summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

# Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

# Create the input string and prep it to pass it to the API
reqbody = '{"input":{"text":"We at FirstLanguage Technologies build state-of-the-art NLP APIsolutions for your\
business at lowest price in the market. FirstLanguageTechnologies was founded in the year 2021 with a mission\
to spread NLP technology across the world. NLP for the masses is our motto. We provide API services which\
are simple to use, easy to integrate and can be understood very easily by anyone.\
FirstLanguage provides basics APIssuch as, stemmer, POS Tagger, Morphological Analyzer.\
and Lemmatizer. The advanced APIs provided by FirstLanguage are,Question Answering,\
Table Question Answering, Summarization and Machine Translation. \
All these APIs are built using state-of-the art deeplearning models fine tuned by us \
and works for 100 plus languages.","lang":"en"} }'
body = jsonpickle.decode(reqbody)

# Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

# Call the corresponding API
res = adv_api_controller.get_summary(body)

print(res.summary)

# From URL:
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://docs.google.com/document/d/1p8ER__mGPlu59zCrqH1PxNNao92qBsq-/export?format=docx",
"utf-8").decode("unicode_escape")

body["input"]["lang"] = "en"
body["input"]["url"] = decoded_url
body["input"]["contentType"] = "docx"


# Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

# Call the corresponding API
res = adv_api_controller.get_summary(body)

print(res.summary)
44 changes: 44 additions & 0 deletions examples/Advanced/example_TableQA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#Create the input string and prep it to pass it to the API
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"]} }'
body = jsonpickle.decode(reqbody)

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_table_qa(body)

for item in result:
print("Query: ",item.query)
print("Answers: ",item.answer)




#From URL:
reqbody = '{"input":{"questions":"","url": "","sendBackRows":"false"} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://drive.google.com/uc?id=1IpBFNs4FlRRbDzL_XPtmGHou_Rvc5Mvq", "utf-8").decode("unicode_escape")


body["input"]["url"] = decoded_url
body["input"]["questions"] = ["How many inhabitants in France"]

#Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

#Call the corresponding API
result = adv_api_controller.get_table_qa(body)

for item in result:
print("Query: ",item.query)
print("Answers: ",item.answer)
47 changes: 47 additions & 0 deletions examples/Advanced/example_Translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle
import base64
import io

# Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

# Create the input string and prep it to pass it to the API
reqbody = '{"input":{"text":"Today is a good day","lang":"ta"} }'

body = jsonpickle.decode(reqbody)

# Initialize the corresponding controller Basic or Advacned
adv_api_controller = client.advanced_api

# Call the corresponding API
res = adv_api_controller.get_translate(body)

print(res.generated_text)

# From URL:
#Prepare input
reqbody='{"input":{"lang":"ja","url": "https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "contentType":"pdf","preserveFormat":"true"} }'
body = jsonpickle.decode(reqbody)

# Initialize the corresponding controller Basic or Advacned
advanced_api_controller = client.advanced_api


# Call the corresponding API
result = advanced_api_controller.get_translate(body)

if(body['input']['contentType'] == 'docx'):
with open('output.docx', 'w') as f:
f.write(result.text)
f.close()

if(body['input']['contentType'] == 'pdf'):
with open('output.pdf', 'wb') as f:
f.write(result.text)
f.close()
print("File saved to disk")

44 changes: 44 additions & 0 deletions examples/Basic/example_Lemma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from firstlanguage_python.firstlanguage_client import Client
from firstlanguage_python.configuration import Environment
import jsonpickle

#Init client with apiKey. Environment will always be set to PRODUCTION for now.
client = Client(
apikey='<Your_API_Key>',
environment=Environment.PRODUCTION,)

#Create the input string and prep it to pass it to the API
reqbody='{"input":{"text":"Smiling makes everyone happy","lang":"en"} }'
body = jsonpickle.decode(reqbody)

#Initialize the corresponding controller Basic or Advacned
basic_api_controller = client.basic_api

#Call the corresponding API
result = basic_api_controller.get_lemma(body)

#Parse the result
for res in result:
print("Original Text passed: "+res.original_text)
print("Lemmatized result: "+res.lemmatized)


#From URL:
reqbody = '{"input":{"lang":"","url": "", "contentType":""} }'
body = jsonpickle.decode(reqbody)
decoded_url = bytes("https://drive.google.com/uc?id=1U8z6TUkuGOfhphEYnTuS6LJe3NWdGzFC", "utf-8").decode("unicode_escape")

body["input"]["lang"] = "en"
body["input"]["url"] = decoded_url
body["input"]["contentType"] = "pdf"

#Initialize the corresponding controller Basic or Advacned
basic_api_controller = client.basic_api

#Call the corresponding API
result = basic_api_controller.get_lemma(body)

#Parse the result
for res in result:
print("Original Text passed: "+res.original_text)
print("Lemmatized result: "+res.lemmatized)
Loading