My Streamlit opens the web browser but it shows the json file content

Python version: 3.11.5
Streamlit version: 1.39.0

I’m running this simple code:

st.set_page_config(page_title=“AI APP TO CHAT WITH SQL DB”)
st.header=“ASK ANYTHING ABOUT YOUR DB”
query=st.text_input(“ask question here”)
st.write(“nothing developed now.”)

I’m running it locally from Jupyter notebook with ’ !streamlit run file.py’

First it was giving NameError " “execution_count”: Null" and was not opening the browser.
After I changed that part to “execution_count”: None, it opens it but shows the json code that is in the py file.

Now the browser has the content below which is the same as the content of the py file.

“”"
{
“cells”: [
{
“cell_type”: “code”,
“execution_count”: 2,
“id”: “a7adc597”,
“metadata”: {},
“outputs”: ,
“source”: [
“import streamlit as st\n”,
“from langchain.agents import create_sql_agent\n”,
“from langchain.agents.agent_toolkits import SQLDatabaseToolkit\n”,
“from langchain.agents.agent_types import AgentType\n”,
“from langchain.chat_models import ChatOpenAI\n”,
“from langchain.sql_database import SQLDatabase\n”,
“from langchain.prompts.chat import ChatPromptTemplate\n”,
“from sqlalchemy import create_engine”
]
},
{
“cell_type”: “code”,
“execution_count”: None,
“id”: “60f25d1a”,
“metadata”: {},
“outputs”: [
{
“name”: “stderr”,
“output_type”: “stream”,
“text”: [
“2024-10-23 09:52:45.703 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:45.704 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:45.705 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:45.705 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:45.706 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:45.707 WARNING streamlit.runtime.state.session_state_proxy: Session state does not function when running a script without streamlit run\n”,
“2024-10-23 09:52:45.708 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:46.172 \n”,
" \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n",
" command:\n",
“\n”,
" streamlit run C:\Users\G20002G\AppData\Local\anaconda3\Lib\site-packages\ipykernel_launcher.py [ARGUMENTS]\n",
“2024-10-23 09:52:46.173 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:46.174 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:46.175 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:46.175 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,
“2024-10-23 09:52:46.175 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”
]
}
],
“source”: [
“st.set_page_config(page_title="AI APP TO CHAT WITH SQL DB")\n”,
“st.header="ASK ANYTHING ABOUT YOUR DB"\n”,
“query=st.text_input("ask question here")\n”,
“st.write("nothing developed now.")”
]
},
{
“cell_type”: “code”,
“execution_count”: 3,
“id”: “34a4467f”,
“metadata”: {},
“outputs”: ,
“source”:
}
],
“metadata”: {
“kernelspec”: {
“display_name”: “Python 3 (ipykernel)”,
“language”: “python”,
“name”: “python3”
},
“language_info”: {
“codemirror_mode”: {
“name”: “ipython”,
“version”: 3
},
“file_extension”: “.py”,
“mimetype”: “text/x-python”,
“name”: “python”,
“nbconvert_exporter”: “python”,
“pygments_lexer”: “ipython3”,
“version”: “3.11.5”
}
},
“nbformat”: 4,
“nbformat_minor”: 5
}
“”"

file.py should contain just the code.

I am not changing anything in the file.py. I am just saving the file with the code i posted. It changes to this json type content.
Then when i do streamlit run file.py, it opens the broser with that same content.

the browser shows this:

{“cells”:[{“cell_type”:“code”,“execution_count”:2,“id”:“28d21a98”,“metadata”:{},“outputs”:[{“name”:“stderr”,“output_type”:“stream”,“text”:[“2024-10-23 09:16:36.046 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.047 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.048 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.048 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.049 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.049 WARNING streamlit.runtime.state.session_state_proxy: Session state does not function when running a script without streamlit run\n”,“2024-10-23 09:16:36.050 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.720 \n”," \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n"," command:\n",“\n”," streamlit run C:\Users\G20220E\AppData\Local\anaconda3\Lib\site-packages\ipykernel_launcher.py [ARGUMENTS]\n",“2024-10-23 09:16:36.721 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.721 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.722 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.722 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”,“2024-10-23 09:16:36.723 Thread ‘MainThread’: missing ScriptRunContext! This warning can be ignored when running in bare mode.\n”]}],“source”:[“# import streamlit as st\n”,“# from langchain.agents import create_sql_agent\n”,“# from langchain.agents.agent_toolkits import SQLDatabaseToolkit\n”,“# from langchain.agents.agent_types import AgentType\n”,“# from langchain.chat_models import ChatOpenAI\n”,“# from langchain.sql_database import SQLDatabase\n”,“# from langchain.prompts.chat import ChatPromptTemplate\n”,“# from sqlalchemy import create_engine\n”,“\n”,“st.set_page_config(page_title="AI APP TO CHAT WITH SQL DB")\n”,“st.header="ASK ANYTHING ABOUT YOUR DB"\n”,“query=st.text_input("ask question here")\n”,“st.write("nothing developed now.")”]},{“cell_type”:“code”,“execution_count”:18,“id”:“95c186ed”,“metadata”:{},“outputs”:[{“name”:“stdout”,“output_type”:“stream”,“text”:[“^C\n”]}],“source”:[“!streamlit run Streamlit.py”]},{“cell_type”:“code”,“execution_count”:9,“id”:“05dca462”,“metadata”:{},“outputs”:[{“name”:“stdout”,“output_type”:“stream”,“text”:[“C:\Users\G20220E\AppData\Local\anaconda3\Scripts\n”]}],“source”:[“# import os\n”,“\n”,“# current_working_directory = os.getcwd()\n”,“# print(current_working_directory)”]},{“cell_type”:“code”,“execution_count”:8,“id”:“db02ce12”,“metadata”:{},“outputs”:,“source”:[“# os.chdir (r"C:\Users\G20220E\AppData\Local\anaconda3\Scripts")”]},{“cell_type”:“code”,“execution_count”:14,“id”:“5f0caafa”,“metadata”:{},“outputs”:[{“name”:“stderr”,“output_type”:“stream”,“text”:[“‘st.stop’ is not recognized as an internal or external command,\n”,“operable program or batch file.\n”]}],“source”:[“# !st.stop()”]},{“cell_type”:“code”,“execution_count”:16,“id”:“77f3ac80”,“metadata”:{},“outputs”:[{“name”:“stdout”,“output_type”:“stream”,“text”:[“^C\n”]}],“source”:[“# !streamlit hello”]},{“cell_type”:“code”,“execution_count”:null,“id”:“fee3a68f”,“metadata”:{},“outputs”:,“source”:}],“metadata”:{“kernelspec”:{“display_name”:“Python 3 (ipykernel)”,“language”:“python”,“name”:“python3”},“language_info”:{“codemirror_mode”:{“name”:“ipython”,“version”:3},“file_extension”:“.py”,“mimetype”:“text/x-python”,“name”:“python”,“nbconvert_exporter”:“python”,“pygments_lexer”:“ipython3”,“version”:“3.11.5”}},“nbformat”:4,“nbformat_minor”:5}

it also has those weird warning after import streamlit.

The browser shows this now.

And in my code I only have these lines:
import streamlit as st
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.agents.agent_types import AgentType
from langchain.chat_models import ChatOpenAI
from langchain.sql_database import SQLDatabase
from langchain.prompts.chat import ChatPromptTemplate
from sqlalchemy import create_engine

st.set_page_config(page_title=“AI APP TO CHAT WITH SQL DB”)
st.header=“ASK ANYTHING ABOUT YOUR DB”
query=st.text_input(“ask question here”)
st.write(“nothing developed now.”)

It changes before you do streamlit run file.py? Right after saving it? How do you realize the change?

1 Like

When I open the py file.
this is what it has
{
“cells”: [
{
“cell_type”: “code”,
“execution_count”: 24,
“id”: “5fe872da”,
“metadata”: {
“scrolled”: True
},
“outputs”: ,
“source”: [
“import streamlit as st\n”,
“from langchain.agents import create_sql_agent\n”,
“from langchain.agents.agent_toolkits import SQLDatabaseToolkit\n”,
“from langchain.agents.agent_types import AgentType\n”,
“from langchain.chat_models import ChatOpenAI\n”,
“from langchain.sql_database import SQLDatabase\n”,
“from langchain.prompts.chat import ChatPromptTemplate\n”,
“from sqlalchemy import create_engine\n”,
“\n”,
“st.set_page_config(page_title="AI APP TO CHAT WITH SQL DB")\n”,
“st.header="ASK ANYTHING ABOUT YOUR DB"\n”,
“query=st.text_input("ask question here")\n”,
“st.write("nothing developed now.")”
]
},

{
“cell_type”: “code”,
“execution_count”: 2,
“id”: “7a5832c5”,
“metadata”: {},
“outputs”: ,
“source”:
}
],
“metadata”: {
“kernelspec”: {
“display_name”: “Python 3 (ipykernel)”,
“language”: “python”,
“name”: “python3”
},
“language_info”: {
“codemirror_mode”: {
“name”: “ipython”,
“version”: 3
},
“file_extension”: “.py”,
“mimetype”: “text/x-python”,
“name”: “python”,
“nbconvert_exporter”: “python”,
“pygments_lexer”: “ipython3”,
“version”: “3.11.5”
}
},
“nbformat”: 4,
“nbformat_minor”: 5
}

But it was already open when you saved it, wasn’t it? So you save it, then close it, then you open it again and it has changed?