Browse Source

chore: share

Byaidu 1 năm trước cách đây
mục cha
commit
54c635a50d
2 tập tin đã thay đổi với 10 bổ sung39 xóa
  1. 8 31
      pdf2zh/gui.py
  2. 2 8
      pdf2zh/pdf2zh.py

+ 8 - 31
pdf2zh/gui.py

@@ -694,39 +694,16 @@ with gr.Blocks(
     # gr.Markdown("Technical details", elem_classes=["info-text"])
 
 
-def setup_gui(enable_gradio_share=False):
-    if(enable_gradio_share):
-        try:
-            demo.launch(server_name="0.0.0.0", debug=True, inbrowser=True, share=True)
-        except Exception:
-            print(
-                "Error launching GUI using 0.0.0.0.\nThis may be caused by global mode of proxy software."
-            )
-            try:
-                demo.launch(
-                    server_name="127.0.0.1", debug=True, inbrowser=True, share=True
-                )
-            except Exception:
-                print(
-                    "Error launching GUI using 127.0.0.1.\nThis may be caused by global mode of proxy software."
-                )
-                demo.launch(server_name="0.0.0.0", debug=True, inbrowser=True, share=True)
-    else:
+def setup_gui(share=False):
+    try:
+        demo.launch(server_name="0.0.0.0", debug=True, inbrowser=True, share=share)
+    except Exception:
+        print("Error launching GUI using 0.0.0.0.\nThis may be caused by global mode of proxy software.")
         try:
-            demo.launch(server_name="0.0.0.0", debug=True, inbrowser=True, share=False)
+            demo.launch(server_name="127.0.0.1", debug=True, inbrowser=True, share=share)
         except Exception:
-            print(
-                "Error launching GUI using 0.0.0.0.\nThis may be caused by global mode of proxy software."
-            )
-            try:
-                demo.launch(
-                    server_name="127.0.0.1", debug=True, inbrowser=True, share=False
-                )
-            except Exception:
-                print(
-                    "Error launching GUI using 127.0.0.1.\nThis may be caused by global mode of proxy software.Force enable Gradio sharing feature."
-                )
-                demo.launch(server_name="0.0.0.0", debug=True, inbrowser=True, share=True)
+            print("Error launching GUI using 127.0.0.1.\nThis may be caused by global mode of proxy software.")
+            demo.launch(debug=True, inbrowser=True, share=True)
 
 # For auto-reloading while developing
 if __name__ == "__main__":

+ 2 - 8
pdf2zh/pdf2zh.py

@@ -237,7 +237,6 @@ def create_parser() -> argparse.ArgumentParser:
     )
     parse_params.add_argument(
         "--share",
-        type=str,
         action="store_true",
         help="Enable Gradio Share",
     )
@@ -272,13 +271,8 @@ def main(args: Optional[List[str]] = None) -> int:
         return -1
     if parsed_args.interactive:
         from pdf2zh.gui import setup_gui
-
-        if parse_args.share:
-            setup_gui(True)
-            return 0
-        else:
-            setup_gui()
-            return 0
+        setup_gui(parsed_args.share)
+        return 0
 
     setup_log()
     extract_text(**vars(parsed_args))