Printing in the terminal but not the The Sreamlit app

Summary

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.header('AUTOMATED MULTIPLE CHOICE QUESTION GENERATOR')
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 = file.read().decode('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
        st.write(res)



This is the link to the notebook and python file
notebook: https://github.com/VictorUmunna/MCQ_Generator/blob/master/mcq_generator.ipynb

script: https://github.com/VictorUmunna/MCQ_Generator/blob/master/mcq_generator_utils.py

app 1: https://github.com/VictorUmunna/MCQ_Generator/blob/master/app.py

app 2: https://github.com/VictorUmunna/MCQ_Generator/blob/master/app_2.py

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 https://extras.streamlit.app/Capture

Hope that helps,

Best,

Thank you @arnaud . It worked

1 Like

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