mintlee commited on
Commit
3d1ffb4
·
1 Parent(s): bce4642
Files changed (2) hide show
  1. powerpoint/xml_handling.py +3 -3
  2. test.ipynb +8 -8
powerpoint/xml_handling.py CHANGED
@@ -74,7 +74,7 @@ def extract_text_from_slide(slide, slide_number, translate=False):
74
  props_element.text = json.dumps(shape_data, indent=2)
75
  return slide_element
76
 
77
- def ppt_to_xml_mongodb(ppt_file_id: str, db_name="ppt"):
78
  """
79
  Chuyển PowerPoint từ MongoDB thành XML và lưu vào MongoDB.
80
 
@@ -140,7 +140,7 @@ def ppt_to_xml_mongodb(ppt_file_id: str, db_name="ppt"):
140
 
141
 
142
 
143
- def extract_text_from_xml(file_id=None, filename=None, db_name="ppt", collection_name="original_xml") -> Dict[str, List[str]]:
144
  """
145
  Tải XML từ MongoDB và trích xuất văn bản từ các slide.
146
 
@@ -265,7 +265,7 @@ def adjust_size(original_text, translated_text, data_container):
265
 
266
 
267
 
268
- def update_xml_with_translated_text_mongodb(file_id: str, translated_dict: Dict[str, List[str]], db_name="ppt"):
269
  """
270
  Tải XML từ MongoDB (collection original_xml), cập nhật nội dung dịch, và lưu lại vào collection final_xml.
271
 
 
74
  props_element.text = json.dumps(shape_data, indent=2)
75
  return slide_element
76
 
77
+ def ppt_to_xml_mongodb(ppt_file_id: str, db_name="pptx"):
78
  """
79
  Chuyển PowerPoint từ MongoDB thành XML và lưu vào MongoDB.
80
 
 
140
 
141
 
142
 
143
+ def extract_text_from_xml(file_id=None, filename=None, db_name="pptx", collection_name="original_xml") -> Dict[str, List[str]]:
144
  """
145
  Tải XML từ MongoDB và trích xuất văn bản từ các slide.
146
 
 
265
 
266
 
267
 
268
+ def update_xml_with_translated_text_mongodb(file_id: str, translated_dict: Dict[str, List[str]], db_name="pptx"):
269
  """
270
  Tải XML từ MongoDB (collection original_xml), cập nhật nội dung dịch, và lưu lại vào collection final_xml.
271
 
test.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 5,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -132,11 +132,11 @@
132
  },
133
  {
134
  "cell_type": "code",
135
- "execution_count": 10,
136
  "metadata": {},
137
  "outputs": [],
138
  "source": [
139
- "def delete_all_files_in_collection(collection_name, db_name=\"ppt\"):\n",
140
  " \"\"\"\n",
141
  " Xóa toàn bộ file trong GridFS của MongoDB.\n",
142
  "\n",
@@ -695,17 +695,17 @@
695
  },
696
  {
697
  "cell_type": "code",
698
- "execution_count": 11,
699
  "metadata": {},
700
  "outputs": [
701
  {
702
  "name": "stdout",
703
  "output_type": "stream",
704
  "text": [
705
- "✅ Đã xóa 4 file trong collection 'root_file'\n",
706
- "✅ Đã xóa 1 file trong collection 'final_pptx'\n",
707
- "✅ Đã xóa 1 file trong collection 'original_xml'\n",
708
- "✅ Đã xóa 1 file trong collection 'final_xml'\n"
709
  ]
710
  }
711
  ],
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
132
  },
133
  {
134
  "cell_type": "code",
135
+ "execution_count": 2,
136
  "metadata": {},
137
  "outputs": [],
138
  "source": [
139
+ "def delete_all_files_in_collection(collection_name, db_name=\"pptx\"):\n",
140
  " \"\"\"\n",
141
  " Xóa toàn bộ file trong GridFS của MongoDB.\n",
142
  "\n",
 
695
  },
696
  {
697
  "cell_type": "code",
698
+ "execution_count": 3,
699
  "metadata": {},
700
  "outputs": [
701
  {
702
  "name": "stdout",
703
  "output_type": "stream",
704
  "text": [
705
+ "✅ Đã xóa 2 file trong collection 'root_file'\n",
706
+ "✅ Đã xóa 0 file trong collection 'final_pptx'\n",
707
+ "✅ Đã xóa 0 file trong collection 'original_xml'\n",
708
+ "✅ Đã xóa 0 file trong collection 'final_xml'\n"
709
  ]
710
  }
711
  ],