How to print variables in the console?

Hello, I am getting an error while running an app in the cloud but works locally. I suspect the underlying issue is coming from mismatch in how streamlit handles saved files. So I want to see the variables that get passed to my functions however I tried adding print statements, logs to see what is being passed once I deploy to steamlit but neither of these showed in the console. Does anyone know how to do this?

Thank you

Repo:

Error message post deployment:

[05:32:28] 🐍 Python dependencies were installed from /mount/src/untitledassitanttool/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[05:32:30] 📦 Processed dependencies!



WARNING ⚠️ user config directory '/home/appuser/.config/lancedb' is not writeable, defaulting to '/tmp' or CWD.Alternatively you can define a LANCEDB_CONFIG_DIR environment variable for this path.
[2024-03-05T05:33:34Z WARN  lance::dataset] No existing dataset at /mount/src/untitledassitanttool/src/InformationProcessor/../STM\company_data_08ef266c-4e0c-4595-9201-8cb3ee59685e/pdf_extracted_content.lance, it will be created
2024-03-05 05:33:34.718 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/untitledassitanttool/main.py", line 4, in <module>
    app.main()
  File "/mount/src/untitledassitanttool/src/ui/streamlit_app.py", line 124, in main
    response = generate_llm_response(prompt)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mount/src/untitledassitanttool/src/ui/streamlit_app.py", line 96, in generate_llm_response
    ingestor.file_broker()  # Process files only once
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/mount/src/untitledassitanttool/src/InformationProcessor/ingestors.py", line 62, in file_broker
    self.ingest_pdf(file,  open_ai=self.ai_credentials)
  File "/mount/src/untitledassitanttool/src/InformationProcessor/ingestors.py", line 111, in ingest_pdf
    processed_pdf, size = call_pdf_preprocess(payload, open_ai)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mount/src/untitledassitanttool/src/InformationProcessor/preprocessor.py", line 156, in call_pdf_preprocess
    extracted_text, page_count = pdf_processor.parse_pdf()
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mount/src/untitledassitanttool/src/InformationProcessor/preprocessor.py", line 87, in parse_pdf
    for page_text, images, _ in results:
        ^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object
1 Like

Hi @cmazzoni87,

Thanks for sharing your question with the community! :balloon: Please update your debugging post to include a code snippet and a link to your app’s public GitHub repo – this will allow the community to help you find an answer as quickly as possible. In the meantime, this post will be tagged as needs-more-info.

1 Like

@tonykip thank you for your fast reply. I updated my post as per your recommendations for your review.

1 Like

Hi @cmazzoni87

It seems you want to download your logs, which is accessible when you are signed in to the Community Cloud, then you can click on the “Manage App” button found in the bottom right, then you can click on “Download logs”.

A more detailed account is provided in the Docs:

Hope this helps!

2 Likes

Hi @dataprofessor, thank you for your respose, I am trying to see my variables in the command panel at runtime. The reason is that a method that returns values in my local env is returning none in my deployed app. I suspect it has something to do with cv2 headless package but I cannot confirm this until I can debug my code.

1 Like

The logs are just a download of what is displayed in the command which I pasted in my question. Why do you think downloading the logs would be any different?

1 Like

Don’t forget adding the newline character and encoding the message to bytes.

2 Likes

@Goyo does this shows the variables or the variable names?

2 Likes

Instead of this

print(x)

you do this:

os.write(1, f"{x}\n".encode()) 
3 Likes

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