Add --nowebui flag for pure API mode (#4651)

This commit is contained in:
oobabooga 2023-11-18 23:38:39 -03:00 committed by GitHub
parent 0fa1af296c
commit ef6feedeb2
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 11 deletions

View file

@ -414,6 +414,7 @@ Optionally, you can use the following command-line flags:
| `--api-port API_PORT` | The listening port for the API. | | `--api-port API_PORT` | The listening port for the API. |
| `--api-key API_KEY` | API authentication key. | | `--api-key API_KEY` | API authentication key. |
| `--admin-key ADMIN_KEY` | API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key. | | `--admin-key ADMIN_KEY` | API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key. |
| `--nowebui` | Do not launch the Gradio UI. Useful for launching the API in standalone mode. |
#### Multimodal #### Multimodal

View file

@ -341,4 +341,7 @@ def run_server():
def setup(): def setup():
Thread(target=run_server, daemon=True).start() if shared.args.nowebui:
run_server()
else:
Thread(target=run_server, daemon=True).start()

View file

@ -171,6 +171,7 @@ parser.add_argument('--public-api-id', type=str, help='Tunnel ID for named Cloud
parser.add_argument('--api-port', type=int, default=5000, help='The listening port for the API.') parser.add_argument('--api-port', type=int, default=5000, help='The listening port for the API.')
parser.add_argument('--api-key', type=str, default='', help='API authentication key.') parser.add_argument('--api-key', type=str, default='', help='API authentication key.')
parser.add_argument('--admin-key', type=str, default='', help='API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key.') parser.add_argument('--admin-key', type=str, default='', help='API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key.')
parser.add_argument('--nowebui', action='store_true', help='Do not launch the Gradio UI. Useful for launching the API in standalone mode.')
# Multimodal # Multimodal
parser.add_argument('--multimodal-pipeline', type=str, default=None, help='The multimodal pipeline to use. Examples: llava-7b, llava-13b.') parser.add_argument('--multimodal-pipeline', type=str, default=None, help='The multimodal pipeline to use. Examples: llava-7b, llava-13b.')
@ -201,7 +202,7 @@ for k in ['notebook', 'chat', 'no_stream', 'mul_mat_q', 'use_fast']:
# Security warnings # Security warnings
if args.trust_remote_code: if args.trust_remote_code:
logger.warning('trust_remote_code is enabled. This is dangerous.') logger.warning('trust_remote_code is enabled. This is dangerous.')
if 'COLAB_GPU' not in os.environ: if 'COLAB_GPU' not in os.environ and not args.nowebui:
if args.share: if args.share:
logger.warning("The gradio \"share link\" feature uses a proprietary executable to create a reverse tunnel. Use it with care.") logger.warning("The gradio \"share link\" feature uses a proprietary executable to create a reverse tunnel. Use it with care.")
if any((args.listen, args.share)) and not any((args.gradio_auth, args.gradio_auth_path)): if any((args.listen, args.share)) and not any((args.gradio_auth, args.gradio_auth_path)):

View file

@ -226,13 +226,19 @@ if __name__ == "__main__":
shared.generation_lock = Lock() shared.generation_lock = Lock()
# Launch the web UI if shared.args.nowebui:
create_interface() # Start the API in standalone mode
while True: shared.args.extensions = [x for x in shared.args.extensions if x != 'gallery']
time.sleep(0.5) if shared.args.extensions is not None and len(shared.args.extensions) > 0:
if shared.need_restart: extensions_module.load_extensions()
shared.need_restart = False else:
# Launch the web UI
create_interface()
while True:
time.sleep(0.5) time.sleep(0.5)
shared.gradio['interface'].close() if shared.need_restart:
time.sleep(0.5) shared.need_restart = False
create_interface() time.sleep(0.5)
shared.gradio['interface'].close()
time.sleep(0.5)
create_interface()