Skip to content

Commit 4c147e3

Browse files
authored
Merge pull request #127 from codelion/fix-add-simple-gui
Fix add simple gui
2 parents df6d403 + 618b03e commit 4c147e3

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

optillm.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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():
688689
def 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

711738
if __name__ == "__main__":

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ nbconvert
2020
ipython
2121
ipykernel
2222
peft
23-
bitsandbytes
23+
bitsandbytes
24+
gradio

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="optillm",
5-
version="0.0.21",
5+
version="0.0.22",
66
packages=find_packages(),
77
py_modules=['optillm'],
88
package_data={
@@ -33,6 +33,7 @@
3333
"ipykernel",
3434
"peft",
3535
"bitsandbytes",
36+
"gradio",
3637
],
3738
entry_points={
3839
'console_scripts': [

0 commit comments

Comments
 (0)