Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoscroll for streaming textbox fails #10545

Open
1 task done
easyfacelab opened this issue Feb 7, 2025 · 0 comments
Open
1 task done

Autoscroll for streaming textbox fails #10545

easyfacelab opened this issue Feb 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@easyfacelab
Copy link

easyfacelab commented Feb 7, 2025

Describe the bug

My multi-tabbed app uses multiple Textboxes, one of them to show app logs.
As per the doc, the textbox should always go to the bottom, but that's not true when you switch from one tab to another.
From some reason, I cannot reproduce as easily without these tabs.
On Chrome the problem appears after switching multiple times, sometimes after launching several time the script doing a stream in my example. On Firefox, the problem appears on the first switch between the tabs.
This looks like a pure js issue, and this is precisely why I'm using Gradio, being not a web dev.
Is there a design issue in the way I manage the streams in the callbacks? Or could it be a Gradio limitation?

I'm sharing a minimal reproducer. Thanks for any enlightenment.

Relates: #5417, #6085

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import subprocess
import time
import gradio as gr

def read_external_program():
    # simple bash loop writing into /tmp/log during 20s
    cmd = ['/bin/bash', '-c', 'for ((x=0; x<20; x=x+1)); do echo $x |& tee -a /tmp/log; sleep 1; done; exit 2']
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
    output = ""
    while p.poll() is None:
        output += p.stdout.readline()
        yield output, '0'
    ret = p.wait()
    yield output, ret

def read_logs():
    output = ""
    with open('/tmp/log') as f:
        while True:
            for line in f:
                output += line
                yield output
            time.sleep(0.1)

with gr.Blocks() as demo:
    with gr.Tab('program'):
        prog_out = gr.Textbox(label='program output', interactive=False, lines=10, max_lines=10)
        return_code = gr.Textbox(label='exit code', interactive=False, value='0')
        start_btn = gr.Button('start')
        start_btn.click(read_external_program, None, [prog_out, return_code])
    with gr.Tab('log'):
        logbox = gr.Textbox(label='log file', interactive=False, lines=35, max_lines=35)
        refresh_btn = gr.Button('refresh logs')
        refresh_btn.click(read_logs, None, logbox)

demo.launch()

Screenshot

No response

Logs

System Info

Gradio 5.14.0
Ubuntu 24.04 LTS
Chrome 132.0.6834.83
Firefox 135.0

Severity

Blocking usage of gradio

@easyfacelab easyfacelab added the bug Something isn't working label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant