capradeepgujaran
commited on
Commit
•
f2ae346
1
Parent(s):
75c2b7c
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,6 @@ import time
|
|
6 |
from PIL import Image as PILImage
|
7 |
import io
|
8 |
import os
|
9 |
-
from tempfile import NamedTemporaryFile
|
10 |
-
from pathlib import Path
|
11 |
import base64
|
12 |
|
13 |
def create_monitor_interface():
|
@@ -15,7 +13,7 @@ def create_monitor_interface():
|
|
15 |
|
16 |
class SafetyMonitor:
|
17 |
def __init__(self):
|
18 |
-
self.client = Groq(
|
19 |
self.model_name = "llama-3.2-90b-vision-preview"
|
20 |
self.max_image_size = (128, 128)
|
21 |
|
@@ -52,35 +50,37 @@ def create_monitor_interface():
|
|
52 |
quality=20,
|
53 |
optimize=True)
|
54 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
|
|
55 |
|
56 |
try:
|
57 |
completion = self.client.chat.completions.create(
|
|
|
58 |
messages=[
|
59 |
-
{
|
60 |
-
"role": "user",
|
61 |
-
"content": "You are a workplace safety expert. Analyze the following image for safety concerns."
|
62 |
-
},
|
63 |
-
{
|
64 |
-
"role": "assistant",
|
65 |
-
"content": "I'll analyze the image for workplace safety concerns and provide specific observations."
|
66 |
-
},
|
67 |
{
|
68 |
"role": "user",
|
69 |
"content": [
|
70 |
{
|
71 |
"type": "text",
|
72 |
-
"text": "
|
73 |
},
|
74 |
{
|
75 |
"type": "image_url",
|
76 |
-
"
|
|
|
|
|
77 |
}
|
78 |
]
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
],
|
81 |
-
|
82 |
max_tokens=100,
|
83 |
-
|
|
|
|
|
84 |
)
|
85 |
return completion.choices[0].message.content
|
86 |
except Exception as e:
|
|
|
6 |
from PIL import Image as PILImage
|
7 |
import io
|
8 |
import os
|
|
|
|
|
9 |
import base64
|
10 |
|
11 |
def create_monitor_interface():
|
|
|
13 |
|
14 |
class SafetyMonitor:
|
15 |
def __init__(self):
|
16 |
+
self.client = Groq() # API key handled by environment variable
|
17 |
self.model_name = "llama-3.2-90b-vision-preview"
|
18 |
self.max_image_size = (128, 128)
|
19 |
|
|
|
50 |
quality=20,
|
51 |
optimize=True)
|
52 |
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
53 |
+
image_url = f"data:image/jpeg;base64,{img_base64}"
|
54 |
|
55 |
try:
|
56 |
completion = self.client.chat.completions.create(
|
57 |
+
model=self.model_name,
|
58 |
messages=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
{
|
60 |
"role": "user",
|
61 |
"content": [
|
62 |
{
|
63 |
"type": "text",
|
64 |
+
"text": "Analyze this workplace for safety concerns. List any safety issues, missing PPE, or hazards you observe."
|
65 |
},
|
66 |
{
|
67 |
"type": "image_url",
|
68 |
+
"image_url": {
|
69 |
+
"url": image_url
|
70 |
+
}
|
71 |
}
|
72 |
]
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"role": "assistant",
|
76 |
+
"content": ""
|
77 |
}
|
78 |
],
|
79 |
+
temperature=0.1,
|
80 |
max_tokens=100,
|
81 |
+
top_p=1,
|
82 |
+
stream=False,
|
83 |
+
stop=None
|
84 |
)
|
85 |
return completion.choices[0].message.content
|
86 |
except Exception as e:
|