deepset-ai / haystack

:mag: LLM orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
https://haystack.deepset.ai
Apache License 2.0
14.69k stars 1.72k forks source link

Streamlit 1.12.0 breaks UI random question #3105

Closed anakin87 closed 1 year ago

anakin87 commented 1 year ago

Describe the bug I'm building a Streamlit app, which is tightly based on Haystack UI. I found that, while using Streamlit>=1.12.0 the following lines of code raise an AttributeError: https://github.com/deepset-ai/haystack/blob/3e3ff33cddc30cabd95f4695a5e19799656e73ae/ui/webapp.py#L165-L167

Error message Related to my application (not the original Haystack UI):

Traceback (most recent call last):
  File "/home/anakin87/apps/fact-checking-rocks/venv/lib/python3.7/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "/home/anakin87/apps/fact-checking-rocks/Rock_fact_checker.py", line 129, in <module>
    main()
  File "/home/anakin87/apps/fact-checking-rocks/Rock_fact_checker.py", line 62, in main
    raise st.scriptrunner.script_runner.RerunException(st.scriptrunner.script_requests.RerunData(None))
AttributeError: module 'streamlit' has no attribute 'scriptrunner'

It seems related to that Streamlit PR.

Expected behavior We should make sure that this line works also with the newer Streamlit versions

Proposed Solution

if hasattr(st, 'scriptrunner'):
    raise st.scriptrunner.script_runner.RerunException(st.scriptrunner.script_requests.RerunData(None))
else:
    raise st.runtime.scriptrunner.script_runner.RerunException(
    st.runtime.scriptrunner.script_requests.RerunData("") 
)

If you agree with this solution, I can open a PR that addresses this issue. Otherwise, we can find together a better solution! :smiley:

System:

bogdankostic commented 1 year ago

Hi @anakin87! I guess it makes sense to add your proposed solution given that we require streamlit version just to be < 2. Please go ahead and open a PR :)