cringo commited on
Commit
b57b714
·
verified ·
1 Parent(s): 9ae1588

non-placeholder filenames attempt #6

Browse files
Files changed (1) hide show
  1. app.py +6 -15
app.py CHANGED
@@ -268,19 +268,18 @@ def load_job(job_id: str):
268
  )
269
 
270
 
271
- def start_job(source_file, target_file, source_lang, target_lang,
272
- source_name="", target_name=""):
273
  if source_file is None or target_file is None:
274
  raise gr.Error("Please upload both EPUB files.")
275
 
276
- src_name = source_name if source_name else Path(source_file).name
277
- tgt_name = target_name if target_name else Path(target_file).name
278
 
279
  upload_dir = tempfile.mkdtemp(prefix="bbb_uploads_")
280
  src_path = os.path.join(upload_dir, src_name)
281
  tgt_path = os.path.join(upload_dir, tgt_name)
282
- shutil.copy2(source_file, src_path)
283
- shutil.copy2(target_file, tgt_path)
284
 
285
  job_id = manager.submit(
286
  source_path=src_path,
@@ -305,15 +304,10 @@ with gr.Blocks(title="📚 Bilingual Book Builder") as demo:
305
  storage_hours = JOB_MAX_AGE_SECONDS // 3600
306
  gr.Markdown(f"""
307
  # Bilingual Book Builder
308
-
309
  Upload a **source** (original) EPUB and a **target** (translation) EPUB to create a side‑by‑side bilingual book.
310
-
311
  Processing may take some time, even hours – you can close this page and return later.
312
-
313
  When ready, the bilingual EPUB will be stored for **{storage_hours} hours**.
314
-
315
  You can also run this locally, it's way faster if you have a graphic card (but requires model downloading).
316
-
317
  [⭐ Source Code](https://github.com/kerivin/bilingual-book-builder)
318
  """)
319
 
@@ -324,11 +318,9 @@ with gr.Blocks(title="📚 Bilingual Book Builder") as demo:
324
  with gr.Column():
325
  source_file = gr.File(label="Source EPUB", file_types=[".epub"], value=None)
326
  source_lang = gr.Textbox(label="Source language (en, ru, de)", placeholder="Auto‑detect")
327
- source_name = gr.Textbox(visible=False)
328
  with gr.Column():
329
  target_file = gr.File(label="Target EPUB", file_types=[".epub"], value=None)
330
  target_lang = gr.Textbox(label="Target language (en, ru, de)", placeholder="Auto‑detect")
331
- target_name = gr.Textbox(visible=False)
332
  with gr.Column():
333
  output_file = gr.File(label="Download Bilingual EPUB", interactive=False)
334
  with gr.Row():
@@ -351,8 +343,7 @@ with gr.Blocks(title="📚 Bilingual Book Builder") as demo:
351
 
352
  process_btn.click(
353
  fn=start_job,
354
- inputs=[source_file, target_file, source_lang, target_lang,
355
- source_name, target_name],
356
  outputs=all_outputs,
357
  )
358
 
 
268
  )
269
 
270
 
271
+ def start_job(source_file, target_file, source_lang, target_lang):
 
272
  if source_file is None or target_file is None:
273
  raise gr.Error("Please upload both EPUB files.")
274
 
275
+ src_name = source_file.orig_name if source_file.orig_name else Path(source_file.path).name
276
+ tgt_name = target_file.orig_name if target_file.orig_name else Path(target_file.path).name
277
 
278
  upload_dir = tempfile.mkdtemp(prefix="bbb_uploads_")
279
  src_path = os.path.join(upload_dir, src_name)
280
  tgt_path = os.path.join(upload_dir, tgt_name)
281
+ shutil.copy2(source_file.path, src_path)
282
+ shutil.copy2(target_file.path, tgt_path)
283
 
284
  job_id = manager.submit(
285
  source_path=src_path,
 
304
  storage_hours = JOB_MAX_AGE_SECONDS // 3600
305
  gr.Markdown(f"""
306
  # Bilingual Book Builder
 
307
  Upload a **source** (original) EPUB and a **target** (translation) EPUB to create a side‑by‑side bilingual book.
 
308
  Processing may take some time, even hours – you can close this page and return later.
 
309
  When ready, the bilingual EPUB will be stored for **{storage_hours} hours**.
 
310
  You can also run this locally, it's way faster if you have a graphic card (but requires model downloading).
 
311
  [⭐ Source Code](https://github.com/kerivin/bilingual-book-builder)
312
  """)
313
 
 
318
  with gr.Column():
319
  source_file = gr.File(label="Source EPUB", file_types=[".epub"], value=None)
320
  source_lang = gr.Textbox(label="Source language (en, ru, de)", placeholder="Auto‑detect")
 
321
  with gr.Column():
322
  target_file = gr.File(label="Target EPUB", file_types=[".epub"], value=None)
323
  target_lang = gr.Textbox(label="Target language (en, ru, de)", placeholder="Auto‑detect")
 
324
  with gr.Column():
325
  output_file = gr.File(label="Download Bilingual EPUB", interactive=False)
326
  with gr.Row():
 
343
 
344
  process_btn.click(
345
  fn=start_job,
346
+ inputs=[source_file, target_file, source_lang, target_lang],
 
347
  outputs=all_outputs,
348
  )
349