Skip to content

Commit

Permalink
fixed update of the table summary attribute, added action icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefbaranec committed Dec 12, 2024
1 parent 99393fd commit f6886fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 23 additions & 4 deletions src/process_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f6886fa

Please sign in to comment.