| 40 | scenex_api_url: str = "us-central1-causal-diffusion.cloudfunctions.net" |
| 41 | |
| 42 | def _describe_image(self, image: str) -> str: |
| 43 | local_image_path = image |
| 44 | data = { |
| 45 | "data": [ |
| 46 | {"image": _image_to_data_uri(local_image_path), "features": []}, |
| 47 | ] |
| 48 | } |
| 49 | |
| 50 | headers = { |
| 51 | "x-api-key": f"token {self.scenex_api_key}", |
| 52 | "content-type": "application/json", |
| 53 | } |
| 54 | |
| 55 | connection = http.client.HTTPSConnection( |
| 56 | "us-central1-causal-diffusion.cloudfunctions.net" |
| 57 | ) |
| 58 | connection.request("POST", "/describe", json.dumps(data), headers) |
| 59 | response = connection.getresponse() |
| 60 | response_data = response.read().decode("utf-8") |
| 61 | response_data = json.loads(response_data) |
| 62 | output = response_data["result"][0]["text"] |
| 63 | connection.close() |
| 64 | return output |
| 65 | |
| 66 | @root_validator(pre=True) |
| 67 | def validate_environment(cls, values: Dict) -> Dict: |