Petch DS commited on
Commit
76fa87f
·
1 Parent(s): 63e61ad

fix bug doesn't find original translated

Browse files
Files changed (2) hide show
  1. translator_app.ipynb +12 -9
  2. translator_app.py +6 -1
translator_app.ipynb CHANGED
@@ -20,7 +20,7 @@
20
  },
21
  {
22
  "cell_type": "code",
23
- "execution_count": 27,
24
  "metadata": {},
25
  "outputs": [],
26
  "source": [
@@ -35,7 +35,7 @@
35
  },
36
  {
37
  "cell_type": "code",
38
- "execution_count": 28,
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
@@ -51,7 +51,7 @@
51
  },
52
  {
53
  "cell_type": "code",
54
- "execution_count": 29,
55
  "metadata": {},
56
  "outputs": [],
57
  "source": [
@@ -74,7 +74,7 @@
74
  },
75
  {
76
  "cell_type": "code",
77
- "execution_count": 30,
78
  "metadata": {},
79
  "outputs": [],
80
  "source": [
@@ -131,7 +131,7 @@
131
  },
132
  {
133
  "cell_type": "code",
134
- "execution_count": 31,
135
  "metadata": {
136
  "colab": {
137
  "base_uri": "https://localhost:8080/",
@@ -284,7 +284,7 @@
284
  },
285
  {
286
  "cell_type": "code",
287
- "execution_count": 43,
288
  "metadata": {},
289
  "outputs": [],
290
  "source": [
@@ -361,7 +361,10 @@
361
  " else:\n",
362
  " print(f\"⚠ Warning: No '_translated' columns found for table at paragraph {table_number}\")\n",
363
  " else:\n",
364
- " doc.add_paragraph(row[\"original_translated\"])\n",
 
 
 
365
  "\n",
366
  " doc.save(output_path)\n",
367
  " return output_path\n",
@@ -414,7 +417,7 @@
414
  },
415
  {
416
  "cell_type": "code",
417
- "execution_count": 44,
418
  "metadata": {
419
  "id": "x8Njoc4fROSp"
420
  },
@@ -460,7 +463,7 @@
460
  "data": {
461
  "text/plain": []
462
  },
463
- "execution_count": 44,
464
  "metadata": {},
465
  "output_type": "execute_result"
466
  }
 
20
  },
21
  {
22
  "cell_type": "code",
23
+ "execution_count": 1,
24
  "metadata": {},
25
  "outputs": [],
26
  "source": [
 
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": 2,
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
 
51
  },
52
  {
53
  "cell_type": "code",
54
+ "execution_count": 3,
55
  "metadata": {},
56
  "outputs": [],
57
  "source": [
 
74
  },
75
  {
76
  "cell_type": "code",
77
+ "execution_count": 4,
78
  "metadata": {},
79
  "outputs": [],
80
  "source": [
 
131
  },
132
  {
133
  "cell_type": "code",
134
+ "execution_count": 5,
135
  "metadata": {
136
  "colab": {
137
  "base_uri": "https://localhost:8080/",
 
284
  },
285
  {
286
  "cell_type": "code",
287
+ "execution_count": 8,
288
  "metadata": {},
289
  "outputs": [],
290
  "source": [
 
361
  " else:\n",
362
  " print(f\"⚠ Warning: No '_translated' columns found for table at paragraph {table_number}\")\n",
363
  " else:\n",
364
+ " if \"original_translated\" in row:\n",
365
+ " doc.add_paragraph(row[\"original_translated\"])\n",
366
+ " else:\n",
367
+ " doc.add_paragraph(\"\")\n",
368
  "\n",
369
  " doc.save(output_path)\n",
370
  " return output_path\n",
 
417
  },
418
  {
419
  "cell_type": "code",
420
+ "execution_count": 9,
421
  "metadata": {
422
  "id": "x8Njoc4fROSp"
423
  },
 
463
  "data": {
464
  "text/plain": []
465
  },
466
+ "execution_count": 9,
467
  "metadata": {},
468
  "output_type": "execute_result"
469
  }
translator_app.py CHANGED
@@ -249,7 +249,10 @@ def reconstruct_word(paragraph_df, translated_tables, file_path):
249
  else:
250
  print(f"⚠ Warning: No '_translated' columns found for table at paragraph {table_number}")
251
  else:
252
- doc.add_paragraph(row["original_translated"])
 
 
 
253
 
254
  doc.save(output_path)
255
  return output_path
@@ -288,6 +291,8 @@ def chat_gpt_translate_word(file, sheet_name, col_name, source_lang, target_lang
288
  os.remove('extracted_tables.xlsx')
289
  if os.path.exists('extracted_tables_translated.xlsx'):
290
  os.remove('extracted_tables_translated.xlsx')
 
 
291
  if os.path.exists(f"{file.split('.')[0]}_translated.xlsx"):
292
  os.remove(f"{file.split('.')[0]}_translated.xlsx")
293
 
 
249
  else:
250
  print(f"⚠ Warning: No '_translated' columns found for table at paragraph {table_number}")
251
  else:
252
+ if "original_translated" in row:
253
+ doc.add_paragraph(row["original_translated"])
254
+ else:
255
+ doc.add_paragraph("")
256
 
257
  doc.save(output_path)
258
  return output_path
 
291
  os.remove('extracted_tables.xlsx')
292
  if os.path.exists('extracted_tables_translated.xlsx'):
293
  os.remove('extracted_tables_translated.xlsx')
294
+
295
+ # for deploy huggingface
296
  if os.path.exists(f"{file.split('.')[0]}_translated.xlsx"):
297
  os.remove(f"{file.split('.')[0]}_translated.xlsx")
298