Spaces:
Running
Running
metadata
tags:
- gradio-custom-component
- gradio-template-Code
- logging
- subprocess
- process
title: gradio_logsview V0.0.1
colorFrom: gray
colorTo: purple
sdk: docker
pinned: false
license: apache-2.0
Name: gradio_logsview
Description: Visualize logs in your Gradio app
Installation
pip install https://huggingface.co/spaces/Wauplin/gradio_logsview/resolve/main/gradio_logsview-0.0.5-py3-none-any.whl
or add this line to your requirements.txt
:
gradio_logsview@https://huggingface.co/spaces/Wauplin/gradio_logsview/resolve/main/gradio_logsview-0.0.5-py3-none-any.whl
How to run Python code?
With LogsView.run_python
, you can run Python code in a separate process and capture logs in real-time.
You can configure which logs to capture (log level and logger name).
from gradio_logsview import LogsView
def fn_python():
# Run `my_function` in a separate process
# All logs above `INFO` level will be captured and displayed in real-time.
runner = LogsViewRunner() # Initialize the runner
yield from runner.run_python(my_function, log_level=logging.INFO, arg1="value1")
yield runner.log(f"Runner: {runner}") # Log any message
if runner.exit_code != 0:
# Handle error
...
with gr.Blocks() as demo:
logs = LogsView()
btn = gr.Button("Run Python code")
btn.click(fn_python, outputs=logs)
How to run a command?
With LogsView.run_command
, you can run a command on the system and capture logs from the process in real-time.
from gradio_logsview import LogsView
def fn_command():
# Run a command and capture all logs from the subprocess
runner = LogsViewRunner() # Initialize the runner
yield from runner.run_command(
cmd=["mergekit-yaml", "config.yaml", "merge", "--copy-", "--cuda", "--low-cpu-memory"]
)
yield runner.log(f"Runner: {runner}") # Log any message
if runner.exit_code != 0:
# Handle error
...
with gr.Blocks() as demo:
logs = LogsView()
btn = gr.Button("Run command")
btn.click(fn_command, outputs=logs)
TODO
- display logs with colors (front-end)
- format logs client-side (front-end)
- scrollable logs if more than N lines (front-end)
- format each log only once (front-end)
- stop process if
run_command
gets cancelled (back-end) - correctly pass error stacktrace in
run_python
(back-end) - correctly catch print statements in
run_python
(back-end) - disable interactivity + remove all code editing logic (both?)
- how to handle progress bars? (i.e when logs are overwritten in terminal)
- Have 3 tabs in UI for stdout, stderr and logging (front-end + back-end)
- Write logger name in the logs (back-end)