Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,18 +84,16 @@ def analyze_mixed_input(input_files):
|
|
| 84 |
"If it does, identify any safety issues or hazards, categorize them, and provide a detailed description, "
|
| 85 |
"and suggest steps to resolve them. If it's not a construction site, simply state that")
|
| 86 |
|
| 87 |
-
for i,
|
| 88 |
-
file_type =
|
| 89 |
if file_type in ['jpg', 'jpeg', 'png', 'bmp']:
|
| 90 |
# Process image
|
| 91 |
-
|
| 92 |
-
resized_image = resize_image(image)
|
| 93 |
-
image_data_url = f"data:image/png;base64,{encode_image(resized_image)}"
|
| 94 |
content_type = "image"
|
| 95 |
elif file_type in ['mp4', 'avi', 'mov', 'webm']:
|
| 96 |
# Process video
|
| 97 |
-
frames = extract_frames_from_video(
|
| 98 |
-
|
| 99 |
content_type = "video"
|
| 100 |
else:
|
| 101 |
results.append((f"File {i+1} analysis", f"Unsupported file type: {file_type}"))
|
|
@@ -112,12 +110,13 @@ def analyze_mixed_input(input_files):
|
|
| 112 |
{
|
| 113 |
"type": "image_url",
|
| 114 |
"image_url": {
|
| 115 |
-
"url":
|
| 116 |
}
|
| 117 |
}
|
| 118 |
]
|
| 119 |
}
|
| 120 |
]
|
|
|
|
| 121 |
completion = client.chat.completions.create(
|
| 122 |
model="llama-3.2-90b-vision-preview",
|
| 123 |
messages=messages,
|
|
@@ -133,7 +132,7 @@ def analyze_mixed_input(input_files):
|
|
| 133 |
# If it's a video, analyze additional frames
|
| 134 |
if content_type == "video" and len(frames) > 1:
|
| 135 |
for j, frame in enumerate(frames[1:], start=2):
|
| 136 |
-
|
| 137 |
messages = [
|
| 138 |
{
|
| 139 |
"role": "user",
|
|
@@ -145,7 +144,7 @@ def analyze_mixed_input(input_files):
|
|
| 145 |
{
|
| 146 |
"type": "image_url",
|
| 147 |
"image_url": {
|
| 148 |
-
"url":
|
| 149 |
}
|
| 150 |
}
|
| 151 |
]
|
|
|
|
| 84 |
"If it does, identify any safety issues or hazards, categorize them, and provide a detailed description, "
|
| 85 |
"and suggest steps to resolve them. If it's not a construction site, simply state that")
|
| 86 |
|
| 87 |
+
for i, file_path in enumerate(input_files):
|
| 88 |
+
file_type = file_path.split('.')[-1].lower()
|
| 89 |
if file_type in ['jpg', 'jpeg', 'png', 'bmp']:
|
| 90 |
# Process image
|
| 91 |
+
image_data = encode_image(file_path)
|
|
|
|
|
|
|
| 92 |
content_type = "image"
|
| 93 |
elif file_type in ['mp4', 'avi', 'mov', 'webm']:
|
| 94 |
# Process video
|
| 95 |
+
frames = extract_frames_from_video(file_path)
|
| 96 |
+
image_data = encode_image(frames[0]) # Use the first frame
|
| 97 |
content_type = "video"
|
| 98 |
else:
|
| 99 |
results.append((f"File {i+1} analysis", f"Unsupported file type: {file_type}"))
|
|
|
|
| 110 |
{
|
| 111 |
"type": "image_url",
|
| 112 |
"image_url": {
|
| 113 |
+
"url": f"data:image/jpeg;base64,{image_data}"
|
| 114 |
}
|
| 115 |
}
|
| 116 |
]
|
| 117 |
}
|
| 118 |
]
|
| 119 |
+
|
| 120 |
completion = client.chat.completions.create(
|
| 121 |
model="llama-3.2-90b-vision-preview",
|
| 122 |
messages=messages,
|
|
|
|
| 132 |
# If it's a video, analyze additional frames
|
| 133 |
if content_type == "video" and len(frames) > 1:
|
| 134 |
for j, frame in enumerate(frames[1:], start=2):
|
| 135 |
+
frame_data = encode_image(frame)
|
| 136 |
messages = [
|
| 137 |
{
|
| 138 |
"role": "user",
|
|
|
|
| 144 |
{
|
| 145 |
"type": "image_url",
|
| 146 |
"image_url": {
|
| 147 |
+
"url": f"data:image/jpeg;base64,{frame_data}"
|
| 148 |
}
|
| 149 |
}
|
| 150 |
]
|