iljung1106 commited on
Commit
1262a0d
·
1 Parent(s): 81d425d

fixed web ui gradio.

Browse files
Files changed (1) hide show
  1. webui_gradio.py +14 -2
webui_gradio.py CHANGED
@@ -83,6 +83,18 @@ _patch_fastapi_starlette_middleware_unpack()
83
 
84
  import gradio as gr
85
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  def _patch_gradio_client_bool_jsonschema() -> None:
87
  """
88
  Work around gradio_client JSON-schema parsing bug where it assumes schema is a dict,
@@ -434,12 +446,12 @@ if __name__ == "__main__":
434
  _patch_fastapi_starlette_middleware_unpack()
435
 
436
  try:
437
- demo.launch(server_name=args.host, server_port=args.port, show_api=False, share=args.share)
438
  except ValueError as e:
439
  # Some environments block localhost checks; fall back to share link.
440
  msg = str(e)
441
  if "localhost is not accessible" in msg and not args.share:
442
- demo.launch(server_name=args.host, server_port=args.port, show_api=False, share=True)
443
  else:
444
  raise
445
 
 
83
 
84
  import gradio as gr
85
 
86
+ def _launch_compat(demo: gr.Blocks, **kwargs):
87
+ """
88
+ Launch Gradio across versions by only passing supported kwargs.
89
+ Some versions don't support e.g. `show_api=...`.
90
+ """
91
+ import inspect
92
+
93
+ sig = inspect.signature(demo.launch)
94
+ allowed = set(sig.parameters.keys())
95
+ safe_kwargs = {k: v for k, v in kwargs.items() if k in allowed}
96
+ return demo.launch(**safe_kwargs)
97
+
98
  def _patch_gradio_client_bool_jsonschema() -> None:
99
  """
100
  Work around gradio_client JSON-schema parsing bug where it assumes schema is a dict,
 
446
  _patch_fastapi_starlette_middleware_unpack()
447
 
448
  try:
449
+ _launch_compat(demo, server_name=args.host, server_port=args.port, show_api=False, share=args.share)
450
  except ValueError as e:
451
  # Some environments block localhost checks; fall back to share link.
452
  msg = str(e)
453
  if "localhost is not accessible" in msg and not args.share:
454
+ _launch_compat(demo, server_name=args.host, server_port=args.port, show_api=False, share=True)
455
  else:
456
  raise
457