import os import gradio as gr from packaging import version from swift.ui.base import all_langs from swift.ui.llm_eval.llm_eval import LLMEval from swift.ui.llm_export.llm_export import LLMExport from swift.ui.llm_infer.llm_infer import LLMInfer from swift.ui.llm_train.llm_train import LLMTrain lang = os.environ.get('SWIFT_UI_LANG', all_langs[0]) locale_dict = { 'title': { 'zh': '🚀SWIFT: 轻量级大模型训练推理框架', 'en': '🚀SWIFT: Scalable lightWeight Infrastructure for Fine-Tuning and Inference' }, 'sub_title': { 'zh': '请查看 ' 'SWIFT 文档来查看更多功能,使用SWIFT_UI_LANG=en环境变量来切换英文界面', 'en': 'Please check ' 'SWIFT Documentation for more usages, Use SWIFT_UI_LANG=zh variable to switch to Chinese UI', }, 'star_beggar': { 'zh': '喜欢SWIFT就动动手指给我们加个star吧🥺 ', 'en': 'If you like SWIFT, ' 'please take a few seconds to star us🥺 ' }, } is_spaces = True if 'SPACE_ID' in os.environ else False if is_spaces: is_shared_ui = True if 'modelscope/swift' in os.environ['SPACE_ID'] else False else: is_shared_ui = False def run_ui(): LLMTrain.set_lang(lang) LLMInfer.set_lang(lang) LLMExport.set_lang(lang) LLMEval.set_lang(lang) with gr.Blocks(title='SWIFT WebUI') as app: gr.HTML(f"

{locale_dict['title'][lang]}

") gr.HTML(f"

{locale_dict['sub_title'][lang]}

") gr.HTML(f"

{locale_dict['star_beggar'][lang]}

") if is_shared_ui: gr.HTML( f'

If the waiting queue is too long, you can either run locally or duplicate the Space and run it on your own profile using a (paid) private A10G-large GPU for training. A A10G-large costs US$3.15/h.   Duplicate Space

' # noqa ) with gr.Tabs(): if is_shared_ui: LLMInfer.build_ui(LLMInfer) LLMTrain.build_ui(LLMTrain) LLMExport.build_ui(LLMExport) LLMEval.build_ui(LLMEval) else: LLMTrain.build_ui(LLMTrain) LLMInfer.build_ui(LLMInfer) LLMExport.build_ui(LLMExport) LLMEval.build_ui(LLMEval) port = os.environ.get('WEBUI_PORT', None) concurrent = {} if version.parse(gr.__version__) < version.parse('4.0.0') and os.environ.get('MODELSCOPE_ENVIRONMENT') != 'studio': concurrent = {'concurrency_count': 5} app.queue(**concurrent).launch( server_name=os.environ.get('WEBUI_SERVER', None), server_port=port if port is None else int(port), height=800, share=bool(int(os.environ.get('WEBUI_SHARE', '0'))))