Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,9 @@ def analyze_construction_media(media):
|
|
99 |
if file_type in ['jpg', 'jpeg', 'png', 'gif']:
|
100 |
# Handle image
|
101 |
try:
|
102 |
-
|
|
|
|
|
103 |
logger.info(f"Image {i+1} encoded, size: {len(image_base64)} bytes")
|
104 |
|
105 |
messages = [
|
@@ -113,7 +115,7 @@ def analyze_construction_media(media):
|
|
113 |
{
|
114 |
"type": "image_url",
|
115 |
"image_url": {
|
116 |
-
"url": f"data:image/
|
117 |
}
|
118 |
}
|
119 |
]
|
@@ -145,7 +147,7 @@ def analyze_construction_media(media):
|
|
145 |
frames = extract_frames_from_video(file_path)
|
146 |
logger.info(f"Extracted {len(frames)} frames from video: {file_path}")
|
147 |
for j, frame in enumerate(frames):
|
148 |
-
frame_base64 =
|
149 |
logger.info(f"Video {i+1}, Frame {j+1} encoded, size: {len(frame_base64)} bytes")
|
150 |
|
151 |
messages = [
|
|
|
99 |
if file_type in ['jpg', 'jpeg', 'png', 'gif']:
|
100 |
# Handle image
|
101 |
try:
|
102 |
+
with Image.open(file_path) as img:
|
103 |
+
img = img.convert('RGB') # Convert to RGB to ensure compatibility
|
104 |
+
image_base64 = encode_image(img)
|
105 |
logger.info(f"Image {i+1} encoded, size: {len(image_base64)} bytes")
|
106 |
|
107 |
messages = [
|
|
|
115 |
{
|
116 |
"type": "image_url",
|
117 |
"image_url": {
|
118 |
+
"url": f"data:image/png;base64,{image_base64}"
|
119 |
}
|
120 |
}
|
121 |
]
|
|
|
147 |
frames = extract_frames_from_video(file_path)
|
148 |
logger.info(f"Extracted {len(frames)} frames from video: {file_path}")
|
149 |
for j, frame in enumerate(frames):
|
150 |
+
frame_base64 = encode_image(frame)
|
151 |
logger.info(f"Video {i+1}, Frame {j+1} encoded, size: {len(frame_base64)} bytes")
|
152 |
|
153 |
messages = [
|