Dsiplay Long Text for Text generation App

Hello Streamlit community,

I created a Text Generation App with streamlit and hugging face.
My question is, is there a way to display long texts (Paragraphs) in streamlit.

Is thera a limit to the length of text we can display on the app as the output from the text generation. the following is my code:

if option == “Text Generation”:
st.header(“Text Generation”)

st.subheader("Enter a sentence you want to generate a blog")
text = st.text_area("Enter a paragraph", height=150)
max_length = st.number_input("Chose the max_length")
if st.button("Generate"):
    generated_text = text_generation(text)
    st.write(generated_text)

here is the function:
def text_generation(text):
‘’’
ARGS
text: data to be enterred
max_len: maximum number of tokens
min_len: minimum number of tokens
‘’’
max_l = 300
inputs = gen_tokenizer.encode(text, return_tensors=‘pt’)
output = gen_model.generate(inputs, max_length=max_l, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
blog = gen_tokenizer.decode(output[0], skip_special_tokens=True)
return blog

When I run this code on Jupyter notebook, it runs fully displaying texts. But in streamlit app it just does not show. very limited maybe maximum 100. is there a limit like that or something?

What should I do?

I cannot run your code because it s neither complete nor properly formatted, but I can write strings of length > 100000 without any issues.

Sorry for that. I did not include the transformers model needed in my post, to run the model. I just shared a snippet of my code.

I just want to know, st.write() has a length limit? like the max amount of characters that it can print out?

If that’s the case, what other options could be used? st.markdown, st.text, do these have any limit?

There is no limit that I am aware of, other than the hardware and the operating system. How long is the text you want to show?

actually, I am letting the user provide the max_length that they want since I am testing out a Blog/Text generation app.

So max to max it should go upto lets say 2000 words or maybe more (ofc depends on the user)

As I said before, I can write more than 100000 characters without issues. That is way more than 2000 words in any language.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.