Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created June 10, 2024 07:15
Show Gist options
  • Save shantanuo/f51564e686e71e2863d49915c9570976 to your computer and use it in GitHub Desktop.
Save shantanuo/f51564e686e71e2863d49915c9570976 to your computer and use it in GitHub Desktop.
Spell check sanskrit wikipedia article using aws lambda function
import re
import boto3
import json
from botocore.config import Config
# https://sa.wikipedia.org/w/index.php?title=भारतीयवायुसेना&diff=486781&oldid=484146
command2 = """भारतीया वायुसेना भारतस्य सशस्त्रसेनायाः कश्चन भागः । सर्वकारीयसुरक्षामन्त्रालयेन नियन्त्रिता इयं संस्था आकाशयुद्धम्,
# copy paste from:
# https://sa.wikipedia.org/wiki/भारतीयवायुसेना
"""
unicode_range = re.compile('[^\u0900-\u097F]+')
command = unicode_range.sub(' ', command2)
session = boto3.Session(
aws_access_key_id='xxx',
aws_secret_access_key='xxx',
region_name='us-east-1'
)
config = Config(
read_timeout=300,
retries={
'max_attempts': 1,
'mode': 'standard'
}
)
lambda_client = session.client('lambda', config=config)
function_name = 'sansnolimit7b'
payload = {
'q': command
}
json_payload = json.dumps(payload)
response = lambda_client.invoke(
FunctionName=function_name,
InvocationType='RequestResponse',
Payload=json_payload
)
response_payload = response['Payload'].read()
response_dict = json.loads(response_payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment