capradeepgujaran
commited on
Commit
•
d4ad3f6
1
Parent(s):
a393b01
Update app.py
Browse files
app.py
CHANGED
@@ -84,16 +84,18 @@ 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 |
content_type = "image"
|
93 |
elif file_type in ['mp4', 'avi', 'mov', 'webm']:
|
94 |
# Process video
|
95 |
-
frames = extract_frames_from_video(
|
96 |
-
|
97 |
content_type = "video"
|
98 |
else:
|
99 |
results.append((f"File {i+1} analysis", f"Unsupported file type: {file_type}"))
|
@@ -110,7 +112,7 @@ def analyze_mixed_input(input_files):
|
|
110 |
{
|
111 |
"type": "image_url",
|
112 |
"image_url": {
|
113 |
-
"url":
|
114 |
}
|
115 |
}
|
116 |
]
|
@@ -132,7 +134,7 @@ def analyze_mixed_input(input_files):
|
|
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 |
-
|
136 |
messages = [
|
137 |
{
|
138 |
"role": "user",
|
@@ -144,7 +146,7 @@ def analyze_mixed_input(input_files):
|
|
144 |
{
|
145 |
"type": "image_url",
|
146 |
"image_url": {
|
147 |
-
"url":
|
148 |
}
|
149 |
}
|
150 |
]
|
|
|
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 in enumerate(input_files):
|
88 |
+
file_type = file.name.split('.')[-1].lower()
|
89 |
if file_type in ['jpg', 'jpeg', 'png', 'bmp']:
|
90 |
# Process image
|
91 |
+
image = Image.open(file.name)
|
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(file.name)
|
98 |
+
image_data_url = f"data:image/png;base64,{encode_image(Image.fromarray(frames[0]))}" # Use the first frame
|
99 |
content_type = "video"
|
100 |
else:
|
101 |
results.append((f"File {i+1} analysis", f"Unsupported file type: {file_type}"))
|
|
|
112 |
{
|
113 |
"type": "image_url",
|
114 |
"image_url": {
|
115 |
+
"url": image_data_url
|
116 |
}
|
117 |
}
|
118 |
]
|
|
|
134 |
# If it's a video, analyze additional frames
|
135 |
if content_type == "video" and len(frames) > 1:
|
136 |
for j, frame in enumerate(frames[1:], start=2):
|
137 |
+
frame_data_url = f"data:image/png;base64,{encode_image(Image.fromarray(frame))}"
|
138 |
messages = [
|
139 |
{
|
140 |
"role": "user",
|
|
|
146 |
{
|
147 |
"type": "image_url",
|
148 |
"image_url": {
|
149 |
+
"url": frame_data_url
|
150 |
}
|
151 |
}
|
152 |
]
|