Spaces:
Sleeping
Sleeping
Update models/gpt4o.py
Browse files- models/gpt4o.py +5 -2
models/gpt4o.py
CHANGED
|
@@ -83,8 +83,11 @@ def run_model(image: Image.Image, api_key: str = None):
|
|
| 83 |
prompt_text = load_prompt()
|
| 84 |
encoded_image = encode_image_base64(image)
|
| 85 |
|
|
|
|
|
|
|
|
|
|
| 86 |
if not api_key:
|
| 87 |
-
return {"json": None, "raw": "⚠️ API key is missing. Please
|
| 88 |
|
| 89 |
client = openai.OpenAI(api_key=api_key)
|
| 90 |
response = client.chat.completions.create(
|
|
@@ -108,4 +111,4 @@ def run_model(image: Image.Image, api_key: str = None):
|
|
| 108 |
full_ocr_text = extract_all_text_pix2struct(image)
|
| 109 |
parsed_json = assign_event_gateway_names_from_ocr(image, parsed_json, full_ocr_text)
|
| 110 |
|
| 111 |
-
return {"json": parsed_json, "raw": output_text}
|
|
|
|
| 83 |
prompt_text = load_prompt()
|
| 84 |
encoded_image = encode_image_base64(image)
|
| 85 |
|
| 86 |
+
# Pull from environment if not passed explicitly
|
| 87 |
+
api_key = api_key or os.getenv("OPENAI_API_KEY")
|
| 88 |
+
|
| 89 |
if not api_key:
|
| 90 |
+
return {"json": None, "raw": "⚠️ API key is missing. Please set it as a secret in your Space or upload it as a file."}
|
| 91 |
|
| 92 |
client = openai.OpenAI(api_key=api_key)
|
| 93 |
response = client.chat.completions.create(
|
|
|
|
| 111 |
full_ocr_text = extract_all_text_pix2struct(image)
|
| 112 |
parsed_json = assign_event_gateway_names_from_ocr(image, parsed_json, full_ocr_text)
|
| 113 |
|
| 114 |
+
return {"json": parsed_json, "raw": output_text}
|