Spaces:
Runtime error
Runtime error
Create vision_engine.py
Browse files- vision_engine.py +23 -0
vision_engine.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
client = OpenAI(base_url="https://integrate.api.nvidia.com/v1", api_key=os.environ["NIM_API_KEY"])
|
| 6 |
+
|
| 7 |
+
def get_elements_from_screenshot(image_path):
|
| 8 |
+
with open(image_path, "rb") as f:
|
| 9 |
+
image_b64 = base64.b64encode(f.read()).decode()
|
| 10 |
+
|
| 11 |
+
completion = client.chat.completions.create(
|
| 12 |
+
model="nvidia/nemotron-3-nano-omni-30b-a3b-reasoning",
|
| 13 |
+
messages=[{
|
| 14 |
+
"role": "user",
|
| 15 |
+
"content": [
|
| 16 |
+
{"type": "text", "text": "Return ONLY valid JSON identifying all interactive elements (name, box, actionable)."},
|
| 17 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}}
|
| 18 |
+
]
|
| 19 |
+
}],
|
| 20 |
+
temperature=0.1
|
| 21 |
+
)
|
| 22 |
+
return completion.choices[0].message.content
|
| 23 |
+
|