@@ -649,7 +649,8 @@ def parse_args():
649649 ("--n" , "OPTILLM_N" , int , 1 , "Number of final responses to be returned" ),
650650 ("--return-full-response" , "OPTILLM_RETURN_FULL_RESPONSE" , bool , False , "Return the full response including the CoT with <thinking> tags" ),
651651 ("--port" , "OPTILLM_PORT" , int , 8000 , "Specify the port to run the proxy" ),
652- ("--log" , "OPTILLM_LOG" , str , "info" , "Specify the logging level" , list (logging_levels .keys ()))
652+ ("--log" , "OPTILLM_LOG" , str , "info" , "Specify the logging level" , list (logging_levels .keys ())),
653+ ("--launch-gui" , "OPTILLM_LAUNCH_GUI" , bool , False , "Launch a Gradio chat interface" )
653654 ]
654655
655656 for arg , env , type_ , default , help_text , * extra in args_env :
@@ -688,8 +689,8 @@ def parse_args():
688689def main ():
689690 global server_config
690691 # Call this function at the start of main()
691- load_plugins ()
692692 args = parse_args ()
693+ load_plugins ()
693694
694695 # Update server_config with all argument values
695696 server_config .update (vars (args ))
@@ -706,6 +707,32 @@ def main():
706707 if server_config_clean ['optillm_api_key' ]:
707708 server_config_clean ['optillm_api_key' ] = '[REDACTED]'
708709 logger .info (f"Server configuration: { server_config_clean } " )
710+
711+ # Launch GUI if requested
712+ if server_config .get ('launch_gui' ):
713+ try :
714+ import gradio as gr
715+ # Start server in a separate thread
716+ import threading
717+ server_thread = threading .Thread (target = app .run , kwargs = {'host' : '0.0.0.0' , 'port' : port })
718+ server_thread .daemon = True
719+ server_thread .start ()
720+
721+ # Configure the base URL for the Gradio interface
722+ base_url = f"http://localhost:{ port } /v1"
723+ logger .info (f"Launching Gradio interface connected to { base_url } " )
724+
725+ # Launch Gradio interface
726+ demo = gr .load_chat (
727+ base_url ,
728+ model = server_config ['model' ],
729+ token = None
730+ )
731+ demo .launch (server_name = "0.0.0.0" , share = False )
732+ except ImportError :
733+ logger .error ("Gradio is required for GUI. Install it with: pip install gradio" )
734+ return
735+
709736 app .run (host = '0.0.0.0' , port = port )
710737
711738if __name__ == "__main__" :
0 commit comments