Printing in the terminal but not the The Sreamlit app


My result prints in the terminal but print โ€˜Noneโ€™ in the web app. Thsi si the code

Steps to reproduce

Code snippet:

import streamlit as st
from mcq_generator_utils import mcq_generation

# Streamlit app header
st.subheader('Generates questions from your text article')

# Upload a text file
file = st.file_uploader("Upload a text file")

def generate_mcq(text):
    mcq = mcq_generation()
    keyword = mcq.extract_keywords(text)
    sentences = mcq.split_text_to_sentences(text)
    mapped_sentences = mcq.map_sentences_to_keywords(keyword, sentences)
    mapped_distractors = mcq.map_distractors(mapped_sentences, mcq.get_word_sense(), mcq.get_distractors_wordnet, mcq.get_distractors_conceptnet)
    result = mcq.print_result(mapped_distractors, mapped_sentences)
    return result

if file is not None:
    text ='utf-8')
    # Process the text and generate MCQs when the button is clicked
    if st.button('Generate'):
        res = generate_mcq(text)
        # Display the generated questions

This is the link to the notebook and python file


app 1:

app 2:

i am willing to enter a meeting with an expert. I need urgent assistance.

Hey @Victor_Umunna! Welcome back to our forum :slight_smile:

The usual print wonโ€™t work in Streamlit apps. Instead, you need to explicitly use Streamlit commands. Generally, you can swap print for st.write in all of the file here and that should do the job!

# Instead of...
print("something I want to see in my app")

# Use...
st.write("something I want to see in my app")

If you really want to stick with calling print, you can also check out the Capture extra here

Hope that helps,


Thank you @arnaud . It worked

1 Like

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