You are a highly Intelligent pyhton coder. Convert this code. Right now this code is…
- User
You are a highly Intelligent pyhton coder. Convert this code. Right now this code is reading images from a folder. I want you to modify this code and read csv file and convert that into a pandas dataframe.
from tqdm.autonotebook import tqdm import json import logging import base64 import boto3 import time import os from botocore.exceptions import ClientError
import pydantic_parser_IN
import pandas as pd logger = logging.getLogger(name) logging.basicConfig(level=logging.INFO) import re
def run_multi_modal_prompt(bedrock_runtime, model_id, messages, max_tokens): """ Invokes a model with a multimodal prompt. Args: bedrock_runtime: The Amazon Bedrock boto3 client. model_id (str): The model ID to use. messages (JSON) : The messages to send to the model. max_tokens (int) : The maximum number of tokens to generate. Returns: None. """
body = json.dumps( { "anthropic_version": "bedrock-2023-05-31", "max_tokens": max_tokens, "messages": messages, "temperature" : 0, "top_p" :0.1, "top_k": 1 } ) response = bedrock_runtime.invoke_model( body=body, modelId=model_id) response_body = json.loads(response.get('body').read()) return response_bodydef get_response(image_path): """ Entrypoint for Anthropic Claude multimodal prompt example. """
try: model_id = 'anthropic.claude-3-5-sonnet-20240620-v1:0' max_tokens = 3000 input_image = image_path input_text = prompt_IN_conf # input_text= pydantic_parser_IN.get_prompt(prompt_IN) # Read reference image from file and encode as base64 strings. with open(input_image, "rb") as image_file: content_image = base64.b64encode(image_file.read()).decode('utf8') # content_image= base64.standard_b64encode(image_file.read()).decode('utf8') message = {"role": "user", "content": [ {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": content_image}}, {"type": "text", "text": input_text} ]} messages = [message] response = run_multi_modal_prompt( bedrock_runtime, model_id, messages, max_tokens) # print(json.dumps(response, indent=4)) return response except ClientError as err: message = err.response["Error"]["Message"] logger.error("A client error occurred: %s", message) print("A client error occured: " + format(message))folder_path = "/home/ritik1s/Desktop/K1 indian data/ k2_inv_new_entities/testing/" file_name = [] response_usage_ip = [] response_usage_op = [] res_time = [] error_filename=[] model_output=[] df=pd.DataFrame() json_output="/home/ritik1s/Desktop/Indian-Multi_pager-20231206T144616Z-001/Indian-Multi_pager/json output/" for file in tqdm(os.listdir(folder_path)): image_path = os.path.join(folder_path,file) start_time = time.time() response = get_response(image_path) response_time = time.time() - start_time try: # json_response=pydantic_parser_IN.get_parsed_output(response=response['content'][0]['text']) json_string =response['content'][0]['text'] file_name.append(file) response_usage_ip.append(response['usage']['input_tokens']) response_usage_op.append(response['usage']['output_tokens']) res_time.append(response_time) # df['input']=df.apply(response_usage_ip)
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.