import boto3
import json
import os
import csv

# Initialize the Bedrock client
client = boto3.client('bedrock-runtime', region_name="us-east-1")

# Function to summarize text using AWS Bedrock
def summarize_text(text, model_id='anthropic.claude-v2'):
    # Prepare the payload for the model
    payload = {
        "prompt": f"\n\nHuman: tolong buat summary dari dokumen ini {text}\n\nAssistant:",
        "max_tokens_to_sample": 500,  # Limit the size of the output
        "temperature": 0.5            # Adjust randomness (between 0 and 1)
    }
   
    # Invoke the model using AWS Bedrock
    response = client.invoke_model(
        modelId=model_id,
        contentType="application/json",
        accept="application/json",
        body=json.dumps(payload)
    )
   
    # Get the response from the model
    result = json.loads(response['body'].read())
   
    # Extract and return the summarized text
    summary = result.get('completion', "No summary available")
    return summary

# Function to read text from a file
def read_text_from_file(file_path):
    with open(file_path, 'r') as file:
        return file.read()
   
myfile = 'myfile.txt' # or if your file is in folder, you can specify the folder as well 'folder/myfile.txt'
mytext = read_text_from_file(myfile)
summary = summarize_text(mytext)

print(summary)