<commit_before><?php

require 'aws.phar';

use Aws\S3\S3Client;
use Aws\S3\Exception;
use Aws\S3\Enum\CannedAcl;
use Aws\Sqs\SqsClient;

$s3Client = S3Client::factory(array(
	'key' => $_SERVER['AWS_ACCESS_KEY_ID'],
	'secret' => $_SERVER['AWS_SECRET_KEY']
));

$sqsClient = SQSClient::factory(array(
	'key' => $_SERVER['AWS_ACCESS_KEY_ID'],
	'secret' => $_SERVER['AWS_SECRET_KEY'],
	'region' => 'us-west-1'
));

$messageJSON = file_get_contents("php://input");
$message = json_decode($messageJSON,true);

$imageId = $message["imageID"];
$url = $message["image"];
$annotationBlob = $message["annotations"];

try {
	// Create image
	$image = imagecreatefromjpeg($url);

	// Create color
	$yellow = imagecolorallocate($image, 255, 243, 96);

	// Set line thickness
	imagesetthickness($image, 5);

	// Loop through annotations
	foreach($annotationBlob as $annotation){
		// Check for rectangle or line annotation
		if ($annotation[0] == 'rect'){
			// Draw rectangle for rectangle annotations
			imagerectangle($image, floatval($annotation[1]), floatval($annotation[2]), floatval($annotation[3]), floatval($annotation[4]), $yellow);
		} else {
			// Draw line for line annotations
			imageline($image, floatval($annotation[1]), floatval($annotation[2]), floatval($annotation[3]), floatval($annotation[4]), $yellow);
		}
	}

	imagejpeg($image,"/tmp/processedImage_".$imageId.".jpg",90);

	$upload = $s3Client->putObject(array(
		'Bucket' => 'bah-reinvent-processed-images',
		'Key'    => $imageId.".jpg",
		'Body'   => file_get_contents("/tmp/processedImage_".$imageId.".jpg"),
		'ACL'	 => CannedAcl::PUBLIC_READ,
		'ContentType' => 'image/jpeg'
	));

	imagedestroy($image);

	// Output header
	ob_start();
	header("HTTP/1.1 200 OK");
	ob_end_flush();

	// Just die already
	die();
} catch (Exception\S3Exception $e) {
	error_log($e->getMessage());

	ob_start();
	header("HTTP/1.1 500 Internal Server Error");
	ob_end_flush();

	die();
}

?><commit_msg>Modified S3 endpoint and region<commit_after><?php

require 'aws.phar';

use Aws\S3\S3Client;
use Aws\S3\Exception;
use Aws\S3\Enum\CannedAcl;
use Aws\Sqs\SqsClient;

$s3Client = S3Client::factory(array(
	'key' => $_SERVER['AWS_ACCESS_KEY_ID'],
	'secret' => $_SERVER['AWS_SECRET_KEY']
));

$sqsClient = SQSClient::factory(array(
	'key' => $_SERVER['AWS_ACCESS_KEY_ID'],
	'secret' => $_SERVER['AWS_SECRET_KEY'],
	'region' => 'us-east-1'
));

$messageJSON = file_get_contents("php://input");
$message = json_decode($messageJSON,true);

$imageId = $message["imageID"];
$url = $message["image"];
$annotationBlob = $message["annotations"];

try {
	// Create image
	$image = imagecreatefromjpeg($url);

	// Create color
	$yellow = imagecolorallocate($image, 255, 243, 96);

	// Set line thickness
	imagesetthickness($image, 5);

	// Loop through annotations
	foreach($annotationBlob as $annotation){
		// Check for rectangle or line annotation
		if ($annotation[0] == 'rect'){
			// Draw rectangle for rectangle annotations
			imagerectangle($image, floatval($annotation[1]), floatval($annotation[2]), floatval($annotation[3]), floatval($annotation[4]), $yellow);
		} else {
			// Draw line for line annotations
			imageline($image, floatval($annotation[1]), floatval($annotation[2]), floatval($annotation[3]), floatval($annotation[4]), $yellow);
		}
	}

	imagejpeg($image,"/tmp/processedImage_".$imageId.".jpg",90);

	$upload = $s3Client->putObject(array(
		'Bucket' => 'nasa-jpl',
		'Key'    => $imageId.".jpg",
		'Body'   => file_get_contents("/tmp/processedImage_".$imageId.".jpg"),
		'ACL'	 => CannedAcl::PUBLIC_READ,
		'ContentType' => 'image/jpeg'
	));

	imagedestroy($image);

	// Output header
	ob_start();
	header("HTTP/1.1 200 OK");
	ob_end_flush();

	// Just die already
	die();
} catch (Exception\S3Exception $e) {
	error_log($e->getMessage());

	ob_start();
	header("HTTP/1.1 500 Internal Server Error");
	ob_end_flush();

	die();
}

?>
{'fraction_non_alphanumeric': 0.19275250578257516, 'fraction_numerical': 0.020303263942431253, 'mean_word_length': 5.328455284552845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1275651', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1385, 'n_words': 258}