(args: Optional[List[str]] = None)
| 244 | |
| 245 | |
| 246 | def main(args: Optional[List[str]] = None) -> int: |
| 247 | from rich.logging import RichHandler |
| 248 | |
| 249 | logging.basicConfig(level=logging.INFO, handlers=[RichHandler()]) |
| 250 | |
| 251 | # disable httpx, openai, httpcore, http11 logs |
| 252 | logging.getLogger("httpx").setLevel("CRITICAL") |
| 253 | logging.getLogger("httpx").propagate = False |
| 254 | logging.getLogger("openai").setLevel("CRITICAL") |
| 255 | logging.getLogger("openai").propagate = False |
| 256 | logging.getLogger("httpcore").setLevel("CRITICAL") |
| 257 | logging.getLogger("httpcore").propagate = False |
| 258 | logging.getLogger("http11").setLevel("CRITICAL") |
| 259 | logging.getLogger("http11").propagate = False |
| 260 | |
| 261 | parsed_args = parse_args(args) |
| 262 | |
| 263 | if parsed_args.config: |
| 264 | ConfigManager.custome_config(parsed_args.config) |
| 265 | |
| 266 | if parsed_args.debug: |
| 267 | log.setLevel(logging.DEBUG) |
| 268 | |
| 269 | if parsed_args.onnx: |
| 270 | ModelInstance.value = OnnxModel(parsed_args.onnx) |
| 271 | else: |
| 272 | ModelInstance.value = OnnxModel.load_available() |
| 273 | |
| 274 | if parsed_args.interactive: |
| 275 | from pdf2zh.gui import setup_gui |
| 276 | |
| 277 | if parsed_args.serverport: |
| 278 | setup_gui( |
| 279 | parsed_args.share, parsed_args.authorized, int(parsed_args.serverport) |
| 280 | ) |
| 281 | else: |
| 282 | setup_gui(parsed_args.share, parsed_args.authorized) |
| 283 | return 0 |
| 284 | |
| 285 | if parsed_args.flask: |
| 286 | from pdf2zh.backend import flask_app |
| 287 | |
| 288 | flask_app.run(port=11008) |
| 289 | return 0 |
| 290 | |
| 291 | if parsed_args.celery: |
| 292 | from pdf2zh.backend import celery_app |
| 293 | |
| 294 | celery_app.start(argv=sys.argv[2:]) |
| 295 | return 0 |
| 296 | |
| 297 | if parsed_args.prompt: |
| 298 | try: |
| 299 | with open(parsed_args.prompt, "r", encoding="utf-8") as file: |
| 300 | content = file.read() |
| 301 | parsed_args.prompt = Template(content) |
| 302 | except Exception: |
| 303 | raise ValueError("prompt error.") |
no test coverage detected