py
import boto3
import pandas as pd
import io
# Read the Parquet file
parquet_file_path = "your_input.parquet" # Replace with your actual file path
df = pd.read_parquet(parquet_file_path)
# Convert DataFrame to Parquet byte stream
buffer = io.BytesIO()
df.to_parquet(buffer, engine="pyarrow")
buffer.seek(0)
# Define the SageMaker endpoint name
endpoint_name = ""
# Create a SageMaker runtime client
runtime = boto3.Session().client("sagemaker-runtime")
# Invoke the SageMaker endpoint
response = runtime.invoke_endpoint(
EndpointName=endpoint_name,
Body=buffer.getvalue(),
ContentType="application/x-parquet"
)
# Read the response
response_body = response["Body"].read()
# Save response as Parquet file
output_df = pd.read_json(io.StringIO(response_body.decode("utf-8"))) # Adjust if response is already in Parquet format
output_df.to_parquet("output.parquet", engine="pyarrow", index=False)
print("Inference result saved as output.parquet")
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)