diff --git a/config.json b/config.json index f119fea..c54cf88 100644 --- a/config.json +++ b/config.json @@ -1,13 +1,13 @@ { "actions": [ { - "name": "Table Summary Generator OpenAI", + "name": "Table Summary Generator with OpenAI", "desc": "A Docker image that automatically generates and applies table summary to PDF files using PDFix SDK and OpenAI", "version": { "major": 1, "minor": 0 }, - "icon": "add_table_summary", + "icon": "table_view", "category": "Tags", "configurations": [ { diff --git a/src/ai.py b/src/ai.py index 21fc28b..2c77a53 100644 --- a/src/ai.py +++ b/src/ai.py @@ -26,7 +26,7 @@ def table_summary(img_path: str, api_key: str, lang: str): "content": [ { "type": "text", - "text": f"Generate summary for the table in {lang} language. Do not output any other text except for generated summaty. If you can't generate any result return just empty string.", + "text": f"Generate summary for the table in {lang} language. Do not output any other text except for generated summaty. If you can't generate any result return just empty string. Use plain text, no markdown format.", }, { "type": "image_url", diff --git a/src/process_pdf.py b/src/process_pdf.py index bbb7616..a03e4c2 100644 --- a/src/process_pdf.py +++ b/src/process_pdf.py @@ -89,12 +89,31 @@ def update_table_sum( response = table_summary(img, api_key, lang) # print(response.message.content) - alt = response.message.content + summary = response.message.content - org_alt = elem.GetAlt() + if not summary or summary == "": + print("[" + img + "] no summary generated") + return + + attr_set = False + attr_dict = None + for index in reversed(range(elem.GetNumAttrObjects())): + attr_obj = elem.GetAttrObject(index) + if not attr_obj: + continue + attr_item = PdsDictionary(attr_obj.obj) + if attr_item.GetText("O") == "Table": + attr_dict = attr_item + break + + if not attr_dict: + attr_dict = doc.CreateDictObject(False) + + old_summary = attr_dict.GetText("Summary") + if overwrite or not old_summary: + print("[" + img + "] summary attribute updated") + attr_dict.PutString("Summary", summary) - if overwrite or not org_alt: - elem.SetAlt(alt) def browse_table_tags(