Spaces:
Runtime error
Runtime error
Download verifyVision.py from SoccerQ/video-analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/SoccerQ/video-analysis/resolve/main/verifyVision.py
- Command line
-
hf download hf://spaces/SoccerQ/video-analysis/verifyVision.py
-
curl -L -o verifyVision.py https://huggingface.co/spaces/SoccerQ/video-analysis/resolve/main/verifyVision.py
1.06 kB
| import base64 | |
| import requests | |
| # OpenAI API Key | |
| api_key = "sk-ag5ACbwMyrvPyr2bdgWqUil--btqA1v88CTr2FAvvnT3BlbkFJo1FrE5Ijx_40rUVPZ5ypwZpD80NtNugaX0ww4dZx0A" | |
| # Function to encode the image | |
| def encode_image(image_path): | |
| with open(image_path, "rb") as image_file: | |
| return base64.b64encode(image_file.read()).decode('utf-8') | |
| # Path to your image | |
| image_path = "path_to_your_image.jpg" | |
| # Getting the base64 string | |
| base64_image = encode_image(image_path) | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": f"Bearer {api_key}" | |
| } | |
| payload = { | |
| "model": "gpt-4o-mini", | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { | |
| "type": "text", | |
| "text": "What’s in this image?" | |
| }, | |
| { | |
| "type": "image_url", | |
| "image_url": { | |
| "url": f"data:image/jpeg;base64,{base64_image}" | |
| } | |
| } | |
| ] | |
| } | |
| ], | |
| "max_tokens": 300 | |
| } | |
| response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) | |
| print(response.json()) |