Upload 2 files
Browse files
app.py
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import time
|
| 5 |
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 6 |
from translate_ppt import translate_pptx
|
|
|
|
| 7 |
|
| 8 |
LANGUAGE_CHOICES = [
|
| 9 |
("韩语", "ko"),
|
|
@@ -25,13 +25,9 @@ LANGUAGE_CHOICES = [
|
|
| 25 |
|
| 26 |
def process_file(file, target_lang, progress=gr.Progress()):
|
| 27 |
output_path = f"translated_{os.path.basename(file.name)}"
|
| 28 |
-
total_units =
|
| 29 |
|
| 30 |
-
|
| 31 |
-
progress(advance=1)
|
| 32 |
-
|
| 33 |
-
# Initial dummy run to count text units for progress
|
| 34 |
-
from pptx import Presentation
|
| 35 |
prs = Presentation(file.name)
|
| 36 |
for slide in prs.slides:
|
| 37 |
for shape in slide.shapes:
|
|
@@ -39,10 +35,15 @@ def process_file(file, target_lang, progress=gr.Progress()):
|
|
| 39 |
for para in shape.text_frame.paragraphs:
|
| 40 |
for run in para.runs:
|
| 41 |
if run.text.strip():
|
| 42 |
-
total_units
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
return out, detected_lang
|
| 47 |
|
| 48 |
def handle_upload(files, target_lang):
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import time
|
|
|
|
| 5 |
from translate_ppt import translate_pptx
|
| 6 |
+
from pptx import Presentation
|
| 7 |
|
| 8 |
LANGUAGE_CHOICES = [
|
| 9 |
("韩语", "ko"),
|
|
|
|
| 25 |
|
| 26 |
def process_file(file, target_lang, progress=gr.Progress()):
|
| 27 |
output_path = f"translated_{os.path.basename(file.name)}"
|
| 28 |
+
total_units = 0
|
| 29 |
|
| 30 |
+
# Count total translatable units
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
prs = Presentation(file.name)
|
| 32 |
for slide in prs.slides:
|
| 33 |
for shape in slide.shapes:
|
|
|
|
| 35 |
for para in shape.text_frame.paragraphs:
|
| 36 |
for run in para.runs:
|
| 37 |
if run.text.strip():
|
| 38 |
+
total_units += 1
|
| 39 |
+
|
| 40 |
+
completed = [0]
|
| 41 |
+
def tick():
|
| 42 |
+
completed[0] += 1
|
| 43 |
+
progress(completed[0], total=total_units)
|
| 44 |
|
| 45 |
+
progress(0, total=total_units, desc="正在翻译中...")
|
| 46 |
+
out, detected_lang = translate_pptx(file.name, output_path, target_lang, progress_callback=tick)
|
| 47 |
return out, detected_lang
|
| 48 |
|
| 49 |
def handle_upload(files, target_lang):
|