Spaces:
Sleeping
Sleeping
File size: 2,545 Bytes
a0aad55 b6c906b a0aad55 b6c906b a0aad55 b6c906b a0aad55 b6c906b a0aad55 b6c906b a0aad55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
from PIL import Image
import os
import anthropic
import base64
from dotenv import load_dotenv
import cv2
from mimetypes import MimeTypes
load_dotenv()
client = anthropic.Anthropic(api_key= os.getenv('ANTHROPIC_API_KEY'))
prompt = """Given 2 construction blueprints your task is to analyze carefully both blueprints and point out difference for following categories in markdown format -
1. Strcutural grid.
2. Layout Areas - rooms , balcony , porch , staircase , elevator etc.
3. Interior changes or optimization.
Summarize all the difference in paragraph concisely in Markdown format .
"""
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
# return base64.b64encode(image_path.getvalue()).decode("utf-8")
def chat_claude(prompt , image1 , image2 ) :
# print("image 1" , image1)
image1_data = encode_image(image1)
# print("image 1 data" , image1_data)
image2_data = encode_image(image2)
mime = MimeTypes()
image1_media_type =mime.guess_type(image1)[0]
image2_media_type =mime.guess_type(image2)[0]
message = client.messages.create(
model="claude-3-opus-20240229",
max_tokens = 4096,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Image 1:"
},
{
"type": "image",
"source": {
"type": "base64",
# "media_type": "image/jpeg",
"media_type": image1_media_type,
"data": image1_data,
},
},
{
"type": "text",
"text": "Image 2:"
},
{
"type": "image",
"source": {
"type": "base64",
# "media_type": "image/jpeg",
"media_type": image2_media_type,
"data": image2_data,
},
},
{
"type": "text",
"text": f"{prompt}"
}
],
}
],
)
return message.content[0].text
|