It’s hard to know exactly why it’s failing, because it’s not clear what Processor is or what it’s doing. If I do something super simple like this with processor.process(), perhaps that will give you a good example.
My guess is that the issue has something to do with the details of either Processor, or perhaps how you are running your app (because of the “missing ScriptRunContext”). Are you just doing streamlit run my_app.py?
Here’s some basic code that works:
import streamlit as st
def mywriter(msg: str):
st.markdown(f"{msg}")
class Processor:
def __init__(self, file, writer):
self.file = file
self.writer = writer
def process(self):
self.writer(f"Processing file: {self.file.name}")
bytestring = self.file.read()
self.writer(f"File size: {len(bytestring)} bytes")
uploaded_file = st.file_uploader("Upload your PDF file", type=["pdf"])
if uploaded_file is not None:
processor = Processor(uploaded_file, mywriter)
processor.process()
The code of the processor is too big. I will prepare a simple example to show. But the point is I’m using the langgraph library so from langgraph.graph StateGraph. I create a Graph and some nodes had the writer and call them. I suppose that the graph object run some code on another context, and that why it is failing. Is there a way to save the actual context on the writer and using it? I’ve tryied with get_script_run_ctx() but there’s no way to use it after.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.