@@ -237,12 +237,12 @@ def translate(
237237 transition: background-color 0.2s ease-in;
238238 }
239239
240- .progress-bar-wrap {
241- border-radius: 8px !important;
242- }
243- .progress-bar {
244- border-radius: 8px !important;
245- }
240+ .progress-bar-wrap {
241+ border-radius: 8px !important;
242+ }
243+ .progress-bar {
244+ border-radius: 8px !important;
245+ }
246246
247247 # .input-file label {
248248 # color: #165DFF !important;
@@ -257,7 +257,7 @@ def translate(
257257 # color: #165DFF !important;
258258 # }
259259 """ ,
260- ) as demo1 :
260+ ) as demo :
261261 gr .Markdown ("# PDFMathTranslate" )
262262
263263 with gr .Row ():
@@ -280,7 +280,7 @@ def translate(
280280 # lang_src = gr.Dropdown(
281281 # label="Source Language",
282282 # info="Which translation service to use. Some require keys",
283- # choices=["Google", "DeepL", "DeepLX", "Azure ", "OpenAI", "Ollama "],
283+ # choices=["Google", "DeepL", "DeepLX", "Ollama ", "Azure "],
284284 # value="Google",
285285 # )
286286 lang_to = gr .Dropdown (
@@ -403,297 +403,6 @@ def on_select_service(value, evt: gr.EventData):
403403 )
404404
405405
406- class EnvSync :
407- """Two-way synchronization between a variable and its system environment counterpart."""
408-
409- def __init__ (self , env_name : str , default_value : str = "" ):
410- self ._name = env_name
411- self ._value = os .environ .get (env_name , default_value )
412- # Initialize the environment variable if it doesn't exist
413- if env_name not in os .environ :
414- os .environ [env_name ] = default_value
415-
416- @property
417- def value (self ) -> str :
418- """Get the current value, ensuring sync with system env."""
419- sys_value = os .environ .get (self ._name )
420- if sys_value != self ._value :
421- self ._value = sys_value
422- return self ._value
423-
424- @value .setter
425- def value (self , new_value : str ):
426- """Set the value and sync with system env."""
427- self ._value = new_value
428- os .environ [self ._name ] = new_value
429-
430- def __str__ (self ) -> str :
431- return self .value
432-
433- def __bool__ (self ) -> bool :
434- return bool (self .value )
435-
436-
437- # Global setup
438- with gr .Blocks (
439- title = "PDFMathTranslate - PDF Translation with preserved formats" ,
440- theme = gr .themes .Default (
441- primary_hue = custom_blue , spacing_size = "md" , radius_size = "lg"
442- ),
443- css = """
444- # .secondary-text {color: #999 !important;}
445- footer {visibility: hidden}
446- .env-warning {color: #dd5500 !important;}
447- .env-success {color: #559900 !important;}
448- .logo {border: transparent;}
449- .logo label {display: none;}
450- .logo .top-panel {display: none;}
451- .title {text-align: center;}
452- .title h1 {color: #999999 !important;}
453- .question {text-align: center;}
454- .question h2 {color: #165DFF !important;}
455- .info-text {text-align: center; margin-top: -5px;}
456- .info-text p {color: #aaaaaa !important;}
457- """ ,
458- ) as demo3 :
459- gr .Markdown (" " , elem_classes = ["title" ])
460- gr .Markdown (" " , elem_classes = ["title" ])
461- gr .Markdown (" " , elem_classes = ["title" ])
462- gr .Markdown (" " , elem_classes = ["title" ])
463- gr .Image ("./docs/images/banner.nocolor.png" , elem_classes = ["logo" ], width = 400 )
464- gr .Markdown ("# Configuration Guide<br/><br/>" , elem_classes = ["title" ])
465- gr .Markdown ("## Use Google Translate?<br/>" , elem_classes = ["question" ])
466- with gr .Row ():
467- gr .Markdown ("" )
468- use_google = gr .Button (
469- "Yes" ,
470- variant = "primary" ,
471- elem_classes = ["secondary-text" ],
472- )
473- use_other = gr .Button (
474- "No" ,
475- variant = "secondary" ,
476- elem_classes = ["secondary-text" ],
477- )
478- gr .Markdown ("" )
479- with gr .Row ():
480- gr .Markdown ("" )
481- gr .Markdown (
482- "Google Translate" ,
483- elem_classes = ["info-text" ],
484- )
485- gr .Markdown (
486- "DeepL, OpenAI, and more" ,
487- elem_classes = ["info-text" ],
488- )
489- gr .Markdown ("" )
490- # gr.Markdown(
491- # """<span class='env-success'>- Properly configured.</span><br>
492- # - GitHub: <a href="https://github.com/Byaidu/PDFMathTranslate">Byaidu/PDFMathTranslate</a><br>
493- # - GUI by: <a href="https://github.com/reycn">Rongxin</a>"""
494- # )
495-
496- with gr .Blocks (
497- title = "PDFMathTranslate - PDF Translation with preserved formats" ,
498- theme = gr .themes .Default (
499- primary_hue = custom_blue , spacing_size = "md" , radius_size = "lg"
500- ),
501- css = """
502- # .secondary-text {color: #999 !important;}
503- footer {visibility: hidden}
504- .env-warning {color: #dd5500 !important;}
505- .env-success {color: #559900 !important;}
506- .logo {border: transparent;
507- height: 10vh;}
508- .logo label {display: none;}
509- .logo .top-panel {display: none;}
510- .title {text-align: center;
511- height: 5vh;}
512- .title h1 {color: #999999 !important;}
513- .question {text-align: center;}
514- .question h2 {color: #165DFF !important;}
515- .info-text {text-align: center; margin-top: -5px;}
516- .info-text p {color: #aaaaaa !important;}
517-
518- @keyframes pulse-background {
519- 0% { background-color: #FFFFFF; }
520- 25% { background-color: #FFFFFF; }
521- 50% { background-color: #E8F3FF; }
522- 75% { background-color: #FFFFFF; }
523- 100% { background-color: #FFFFFF; }
524- }
525-
526- /* Add dashed border to input-file class */
527- .input-file {
528- border: 1.2px dashed #165DFF !important;
529- border-radius: 6px !important;
530- # background-color: #ffffff !important;
531- animation: pulse-background 2s ease-in-out;
532- transition: background-color 0.4s ease-out;
533- width: 80vw;
534- height: 60vh;
535- margin: 0 auto;
536- }
537-
538- .input-file:hover {
539- border: 1.2px dashed #165DFF !important;
540- border-radius: 6px !important;
541- color: #165DFF !important;
542- background-color: #E8F3FF !important;
543- transition: background-color 0.2s ease-in;
544- box-shadow: 4px 4px 20px rgba(22, 93, 255, 0.1);
545- }
546-
547-
548- .input-file label {
549- color: #165DFF !important;
550- border: 1.2px dashed #165DFF !important;
551- border-left: none !important;
552- border-top: none !important;
553- }
554- .input-file .top-panel {
555- color: #165DFF !important;
556- border: 1.2px dashed #165DFF !important;
557- border-right: none !important;
558- border-top: none !important;
559- }
560- .input-file .filename {
561- color: #165DFF !important;
562- background-color: #FFFFFF !important;
563- }
564- .input-file .download {
565- color: #165DFF !important;
566- background-color: #FFFFFF !important;
567- }
568- .input-file .wrap {
569- color: #165DFF !important;
570- }
571- .input-file .or {
572- color: #165DFF !important;
573- }
574-
575- .progress-bar-wrap {
576- border-radius: 8px !important;
577- }
578- .progress-bar {
579- border-radius: 8px !important;
580- }
581-
582- .options-row {
583- align-items: center;
584- display: flex;
585- }
586- .options-row .wrap {
587- align-items: center;
588- justify-content: center;
589- flex-wrap: wrap;
590- gap: 1rem;}
591-
592- .options-row .form label {
593- color: #999;}
594- .options-row .form {
595- border: none !important;
596- align-items: center !important;}
597- .options-row [data-testid="block-info"] {
598- display: none !important;}
599- .logo-row {
600- align-items: center;}
601- .title-row {
602- align-items: center;}
603- .details-row {
604- align-items: center;}
605- .hide-frame {
606- border: none !important;}
607- .hide-frame .top-panel {
608- display: none !important;}
609- .hide-frame label {
610- display: none !important;}
611- .options-icon {
612- height: 2em;
613- width: 2em;
614- }
615- .options-btn {
616- line-height: var(--line-md);
617- background-color: #FFFFFF;
618- border: 1.2px solid var(--checkbox-label-border-color) !important;
619- border-radius: 6px !important;
620- # color: var(--checkbox-label-border-color) !important;
621- color: #999;
622- transition: background-color 0.2s ease-in;
623- }
624- .options-btn:hover {
625- background-color: #fafafa;
626- # border: 1.2px solid #fcfcfc !important;
627- }
628- """ ,
629- ) as demo :
630- with gr .Row (elem_classes = ["logo-row" ]):
631- gr .Image ("./docs/images/banner.nocolor.png" , elem_classes = ["logo" ])
632- with gr .Row (elem_classes = ["title-row" ]):
633- gr .Markdown ("# PDFMathTranslate" , elem_classes = ["title" ])
634- with gr .Row (elem_classes = ["input-file-row" ]):
635- gr .File (
636- label = "Upload PDF" ,
637- file_count = "single" ,
638- file_types = [".pdf" ],
639- interactive = True ,
640- elem_classes = ["input-file" , "secondary-text" ],
641- )
642- with gr .Row (elem_classes = ["options-row" ]):
643- gr .Markdown ("" )
644- # gr.Dropdown(
645- # ["Google", "DeepL", "DeepLX", "Azure", "OpenAI", "Ollama"],
646- # value="Google",
647- # label="Translation Service",
648- # interactive=True,
649- # elem_classes=["secondary-text"],
650- # )
651- # gr.Dropdown(
652- # [
653- # "Chinese",
654- # "English",
655- # "French",
656- # "German",
657- # "Japanese",
658- # "Korean",
659- # "Russian",
660- # "Spanish",
661- # ],
662- # value="Chinese",
663- # label="To",
664- # interactive=True,
665- # elem_classes=["secondary-text"],
666- # scale=2,
667- # )
668- gr .Radio (
669- ["All Pages" , "First Page" , "First 5 Pages" ],
670- value = "All Pages" ,
671- label = "Pages" ,
672- interactive = True ,
673- elem_classes = ["secondary-text" ],
674- scale = 2 ,
675- )
676- gr .Markdown ("" )
677- with gr .Row (elem_classes = ["options-row" ]):
678- gr .Markdown ("" )
679- gr .Markdown ("" )
680- # gr.Image(
681- # "./docs/images/icon/setting-one.png",
682- # elem_classes=["hide-frame", "options-icon"],
683- # scale=1,
684- # )
685- # gr.Markdown("Advanced Settings", elem_classes=["secondary-text"])
686- gr .Button (
687- "⚙️ Advanced Options" ,
688- variant = "secondary" ,
689- elem_classes = ["options-btn" ],
690- )
691- gr .Markdown ("" )
692- gr .Markdown ("" )
693- # with gr.Row(elem_classes=["details-row"]):
694- # gr.Markdown("Technical details", elem_classes=["info-text"])
695-
696-
697406def setup_gui (share = False ):
698407 try :
699408 demo .launch (server_name = "0.0.0.0" , debug = True , inbrowser = True , share = share )
0 commit comments