Mqleet commited on
Commit
4352edb
Β·
1 Parent(s): 14e8c06

upd app file

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -460,7 +460,7 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
460
  qwen_api_key, zhipuai_api_key, openrouter_api_key):
461
  """Start generation process"""
462
  if pdf_file is None:
463
- return "❌ Please upload a PDF file", gr.update(visible=False), "", "", gr.update(), gr.update(), ""
464
 
465
  # Validate API keys
466
  validation_errors = validate_api_keys(
@@ -470,7 +470,7 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
470
 
471
  if validation_errors:
472
  error_msg = "❌ API Key Validation Failed:\n" + "\n".join(f"β€’ {error}" for error in validation_errors)
473
- return error_msg, gr.update(visible=False), "", "", gr.update(), gr.update(), ""
474
 
475
  state.reset()
476
 
@@ -489,7 +489,7 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
489
  try:
490
  matched = matching(template_requirement)
491
  except Exception as e:
492
- return f"❌ Template recommendation failed: {e}", gr.update(visible=False), "", "", gr.update(choices=[], value=None), gr.update(visible=False, value=""), ""
493
 
494
  html_finder_ = HtmlFinder()
495
  with open('templates/template_link.json','r') as f:
@@ -510,14 +510,14 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
510
  continue
511
 
512
  if not previews:
513
- return "❌ No previewable templates found", gr.update(visible=False), "", "", gr.update(choices=[], value=None), gr.update(visible=False, value=""), ""
514
 
515
  md_lines = ["### πŸ” Please select a template to preview before clicking **Start Generation**", ""]
516
  for name, _, url in previews:
517
  md_lines.append(f"- **{name}** β†’ [{url}]({url})")
518
  md = "\n".join(md_lines)
519
 
520
- return "Recommended 3 templates, please select one to continue", gr.update(visible=False), "", "", gr.update(choices=[n for n, _, _ in previews], value=None), gr.update(visible=True, value=md), ""
521
 
522
  template_dir = os.path.join(template_root, template_choice_value)
523
 
@@ -545,7 +545,7 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
545
  )
546
 
547
  if not args.template_dir:
548
- return "❌ Please select a template", gr.update(visible=False), "", "", gr.update(), gr.update(), ""
549
 
550
  if not args.template_file:
551
  html_finder_ = HtmlFinder()
@@ -633,7 +633,7 @@ def start_generation(pdf_file, model_name_t, model_name_v, template_root,
633
  except Exception as e:
634
  import traceback
635
  error_msg = f"❌ Generation failed: {str(e)}\n{traceback.format_exc()}"
636
- return error_msg, gr.update(visible=False), "", "", gr.update(), gr.update(), ""
637
 
638
  def generate_section_initial():
639
  """Generate initial Section"""
 
460
  qwen_api_key, zhipuai_api_key, openrouter_api_key):
461
  """Start generation process"""
462
  if pdf_file is None:
463
+ return "❌ Please upload a PDF file", gr.update(visible=False), "", "", gr.update(), gr.update()
464
 
465
  # Validate API keys
466
  validation_errors = validate_api_keys(
 
470
 
471
  if validation_errors:
472
  error_msg = "❌ API Key Validation Failed:\n" + "\n".join(f"β€’ {error}" for error in validation_errors)
473
+ return error_msg, gr.update(visible=False), "", "", gr.update(), gr.update()
474
 
475
  state.reset()
476
 
 
489
  try:
490
  matched = matching(template_requirement)
491
  except Exception as e:
492
+ return f"❌ Template recommendation failed: {e}", gr.update(visible=False), "", "", gr.update(choices=[], value=None), gr.update(visible=False, value="")
493
 
494
  html_finder_ = HtmlFinder()
495
  with open('templates/template_link.json','r') as f:
 
510
  continue
511
 
512
  if not previews:
513
+ return "❌ No previewable templates found", gr.update(visible=False), "", "", gr.update(choices=[], value=None), gr.update(visible=False, value="")
514
 
515
  md_lines = ["### πŸ” Please select a template to preview before clicking **Start Generation**", ""]
516
  for name, _, url in previews:
517
  md_lines.append(f"- **{name}** β†’ [{url}]({url})")
518
  md = "\n".join(md_lines)
519
 
520
+ return "Recommended 3 templates, please select one to continue", gr.update(visible=False), "", "", gr.update(choices=[n for n, _, _ in previews], value=None), gr.update(visible=True, value=md)
521
 
522
  template_dir = os.path.join(template_root, template_choice_value)
523
 
 
545
  )
546
 
547
  if not args.template_dir:
548
+ return "❌ Please select a template", gr.update(visible=False), "", "", gr.update(), gr.update()
549
 
550
  if not args.template_file:
551
  html_finder_ = HtmlFinder()
 
633
  except Exception as e:
634
  import traceback
635
  error_msg = f"❌ Generation failed: {str(e)}\n{traceback.format_exc()}"
636
+ return error_msg, gr.update(visible=False), "", "", gr.update(), gr.update()
637
 
638
  def generate_section_initial():
639
  """Generate initial Section"""