I am not sure about the streaming strategy within Streamlit but here is a generic hack logic for client-side streaming in case helpful,
import asyncio, shlex, subprocess, sys
async def subprocess_async(cmd, **kwargs):
cmd_list = shlex.split(cmd)
proc = await asyncio.create_subprocess_exec(
*cmd_list,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
**kwargs)
answer = ""
while proc.returncode is None:
buf = await proc.stdout.read(4)
if not buf:
return
buf = buf.decode("utf-8")
print(buf, end="")
sys.stdout.flush()
answer += buf
res = subprocess.CompletedProcess(cmd, proc.returncode, stdout=answer, stderr=b'')
return res
X = """Python is a high-level, interpreted, general-purpose programming language.
It is a powerful and versatile language that is used for a wide range of applications, from web development to data science.
Python is known for its readability and ease of use, making it a great language for beginners.
It also has a large and active community of developers contributing to the language and its libraries.
"""
asyncio.create_task(subprocess_async(f"echo {X}"))