[webui] upgrade webui and fix api (#8460)

This commit is contained in:
Yaowei Zheng
2025-06-25 21:59:58 +08:00
committed by GitHub
parent f276b9a963
commit 4407231a3b
9 changed files with 109 additions and 27 deletions

View File

@@ -15,6 +15,7 @@
from .chatbot import create_chat_box
from .eval import create_eval_tab
from .export import create_export_tab
from .footer import create_footer
from .infer import create_infer_tab
from .top import create_top
from .train import create_train_tab
@@ -24,6 +25,7 @@ __all__ = [
"create_chat_box",
"create_eval_tab",
"create_export_tab",
"create_footer",
"create_infer_tab",
"create_top",
"create_train_tab",

View File

@@ -0,0 +1,42 @@
# Copyright 2025 the LlamaFactory team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING
from ...extras.misc import get_current_memory
from ...extras.packages import is_gradio_available
if is_gradio_available():
import gradio as gr
if TYPE_CHECKING:
from gradio.components import Component
def get_device_memory() -> "gr.Slider":
free, total = get_current_memory()
used = round((total - free) / (1024**3), 2)
total = round(total / (1024**3), 2)
return gr.Slider(minimum=0, maximum=total, value=used, step=0.01)
def create_footer() -> dict[str, "Component"]:
with gr.Row():
device_memory = gr.Slider(interactive=False)
timer = gr.Timer(value=5)
timer.tick(get_device_memory, outputs=[device_memory], queue=False)
return dict(device_memory=device_memory)