mirror of
https://github.com/hiyouga/LlamaFactory.git
synced 2026-02-03 08:53:38 +00:00
[webui] upgrade webui and fix api (#8460)
This commit is contained in:
42
src/llamafactory/webui/components/footer.py
Normal file
42
src/llamafactory/webui/components/footer.py
Normal 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)
|
||||
Reference in New Issue
Block a user