Repository: deepset-ai/haystack

Issue:
Streamlit 1.12.0 breaks UI random question
**Describe the bug**
I'm building a Streamlit app, which is tightly based on [Haystack UI](https://github.com/deepset-ai/haystack/tree/main/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](https://github.com/streamlit/streamlit/pull/5072).

**Expected behavior**
We should make sure that this line works also with the newer Streamlit versions

**Proposed Solution**
```python
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:**
 - OS: Ubuntu 22.04
 - GPU/CPU: CPU
 - Haystack version (commit or version number): 1.7.0
 - Streamlit: 1.12.0



Discussion:
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 :)

Resolving patch:
diff --git a/ui/setup.py b/ui/setup.py
--- a/ui/setup.py
+++ b/ui/setup.py
@@ -36,5 +36,5 @@
     ],
     packages=find_packages(),
     python_requires=">=3.7, <4",
-    install_requires=["streamlit>=1.2.0, <2", "st-annotated-text>=2.0.0, <3", "markdown>=3.3.4, <4"],
+    install_requires=["streamlit>=1.9.0, <2", "st-annotated-text>=2.0.0, <3", "markdown>=3.3.4, <4"],
 )
diff --git a/ui/webapp.py b/ui/webapp.py
--- a/ui/webapp.py
+++ b/ui/webapp.py
@@ -164,7 +164,13 @@ def reset_results(*args):
         st.session_state.random_question_requested = True
         # Re-runs the script setting the random question as the textbox value
         # Unfortunately necessary as the Random Question button is _below_ the textbox
-        raise st.scriptrunner.script_runner.RerunException(st.scriptrunner.script_requests.RerunData(None))
+        if hasattr(st, "scriptrunner"):
+            raise st.scriptrunner.script_runner.RerunException(
+                st.scriptrunner.script_requests.RerunData(widget_states=None)
+            )
+        raise st.runtime.scriptrunner.script_runner.RerunException(
+            st.runtime.scriptrunner.script_requests.RerunData(widget_states=None)
+        )
     st.session_state.random_question_requested = False
 
     run_query = (


Test patch: