Todo app streamlit sqlite3

I wrote a todo app with streamlit. When I upload it, it will be remove after a few hours. How can I give an address in the database?

Links

https://pvc.onrender.com/
https://github.com/abdollahchelasi/pvcramkan-python

This is the address of my project. When it is deployed on the site from GitHub, I upload the file, it is added to the site and it is added to the database. It clears after a few hours. Please give me the code where the problem is

1 Like

Hey @Abdollah_Chelasi!

Thanks for letting us know about the issue you’re having.I

I’m not able to access your GitHub repo, can you make it accessible or paste the relevant code snippets here?

Thanks,
Charly

import streamlit as st, sqlite3
from streamlit_option_menu import option_menu


st.set_page_config(page_title="خدمات PVC - رمکان", page_icon="https://namapoush.ir/wp-content/uploads/2021/06/WhatsApp-Image-2021-06-05-at-12.42.50.jpeg")

selected = option_menu (
    menu_title=None,
    options=["تماس با ما","ورود ادمین","صفحه اصلی"],
    icons=["house","book", "envelope"],
    menu_icon="cast",
    default_index=2,
    orientation="horizontal",
    styles={

        
        "nav-link":{
            'font-family': 'Courier New' 'Courier' 'monospace'
        },
        
    }
)


with st.expander("خدمات PVC - رمکان",expanded=True):

    col1,col2=st.columns(2)

    with col1:
        st.write("خدمات و اجرای نصب pvc با طرح های مختلف - در سر تا سر جزیره قشم")

    with col2: 

      st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQgD3vXk45UtxrEbUektF9sAtgXPr8XPKk_7w&usqp=CAU")
      





# with open('c.css') as f:
#     st.markdown(f'<style>{f.read()}</style>' ,unsafe_allow_html=True)


st.markdown("""<style>
@import url('https://fonts.googleapis.com/css2?family=Lalezar&display=swap');
.css-10trblm.e16nr0p30{
    font-family: 'Lalezar', cursive;
    
    padding: 3px;
    text-align: center;
    text-shadow: black 2px 2px 17px;
    color: rgb(57, 60, 100);
}
.block-container{
    direction: rtl;
}
/* BTN BALA */
.e1fb0mya1.css-fblp2m.ex0cdmw0{
    border-style: groove;
    border-color: black;
    background: linear-gradient(rgb(40, 110, 114),rgb(77, 77, 192),rgb(75, 25, 25));
}
.e1fb0mya1.css-fblp2m.ex0cdmw0:hover{
    
    background: linear-gradient(rgb(10, 243, 255),rgb(37, 37, 252),rgb(255, 34, 34));
}
/* صفحه بالا */
.css-1avcm0n.e8zbici2{
    background: linear-gradient(rgb(7, 17, 9),rgb(44, 44, 83),rgb(5, 58, 59));
}
/* PVC */
.css-10trblm.e16nr0p30{
    color: aliceblue;
    background: linear-gradient(rgb(4, 48, 61),rgb(10, 10, 58),rgb(55, 212, 214));
    border-radius: 5px;
    width: 100%;
}
/* Home */
.main.css-k1vhr4.egzxvld3{
    background: linear-gradient(rgb(5, 42, 44),rgb(5, 5, 19),rgb(14, 8, 8));
}
.css-8ojfln.e1wqxbhn1{
    font-family: 'Lalezar', cursive;
    
}
/* cALL */
.css-183lzff.eyqtai90{
    font-family: 'Lalezar', cursive;
    text-shadow: rgb(87, 61, 7) 1px 1px 9px;
    color: rgb(238, 209, 45);
}
.css-1fv8s86.e16nr0p34 p{
    font-family: 'Lalezar', cursive;
    color: rgb(57, 194, 123);
    text-shadow: rgb(41, 194, 21) 1px 1px 9px;
}
.css-5uatcg.edgvbvh5{
    font-family: 'Lalezar', cursive;
}
.css-1v0mbdj.etr89bj1 img{
    border-style: groove;
    border-color: rgb(8, 55, 99);
    width: 200px;
    height: 150px;
    border-radius: 13px;
    box-shadow: rgb(0, 0, 0) 1px 1px 7px;
    
}
.css-1fv8s86.e16nr0p34 a{
    font-family: 'Lalezar', cursive;
    text-align: center;
    text-decoration: none;
    padding: 5px;
    border-radius: 11px;
    background: linear-gradient(rgb(14, 47, 49),rgb(5, 43, 75),rgb(10, 8, 14));
}
.css-1fv8s86.e16nr0p34 a:hover{
    color: aliceblue;
    border-style: groove;
    border-color: rgb(22, 22, 43);
    background: linear-gradient(rgb(47, 146, 151),rgb(57, 110, 153),rgb(10, 8, 14));
}
/* Label */
.css-1yy6isu.e16nr0p34 p{
    font-family: 'Lalezar', cursive;
    color: rgb(51, 206, 46);
    text-shadow: rgb(161, 245, 65) 1px 1px 9px;
}
/* Navbar */
.css-6qob1r.e1fqkh3o3{
    background: linear-gradient(rgb(5, 5, 19),rgb(5, 42, 44),rgb(14, 8, 8));
}
</style>""" ,unsafe_allow_html=True)








if selected == "ورود ادمین":

	username = st.text_input(label="نام کاربری",placeholder="Username")
	password = st.text_input(label="پسورد",placeholder="password",type="password")
	btnLogin = st.button("ورود")

	if username == "admin" and password == "admin":
		st.success("خوش آمدی ادمین")
		selected = option_menu(options=["پست های ادمین"],
        menu_title=""

        
        
        )
		

	elif username or password == "admin":
		st.error("لطفا درست وارد کنید")







con=sqlite3.connect('picscols.db',check_same_thread=False)

cur=con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS pics(id TEXT, img BLOB, note TEXT)')



if selected == "پست های ادمین":

    

    if st.button('اضافه کردن محصول'):
        cur.execute('INSERT INTO pics(id, img, note) VALUES(?,?,?)', ('', '', ''))
        con.commit()

    for row in cur.execute('SELECT rowid, id, img, note FROM pics ORDER BY id'):
        with st.form(f'ID-{row[0]}', clear_on_submit=True):
            imgcol, notecol = st.columns([3, 2])
            id=notecol.text_input('کد محصول', row[1])
            note=notecol.text_area('نام محصول', row[3])
            if row[2]:
                img=row[2]
                imgcol.image(row[2])
            file=imgcol.file_uploader('تصاویر', ['png', 'jpg', 'gif', 'bmp'])
            if file: 
                img=file.read()
            if notecol.form_submit_button('ذخیره محصول'):
                
                cur.execute(
                    'UPDATE pics SET id=?, img=?, note=? WHERE id=?;', 
                    (id, img, note, str(row[1]))
                    )
                con.commit()
                st.experimental_rerun()
            if notecol.form_submit_button("حذف محصول"):
                cur.execute(f'''DELETE FROM pics WHERE rowid="{row[0]}";''')
                con.commit()
                st.experimental_rerun()




if selected == "صفحه اصلی":



     


     

     

     for row in cur.execute('SELECT rowid, id, img, note FROM pics ORDER BY id'):
        # with st.form(f'ID-{row[0]}', clear_on_submit=True):
        st.write("---")
        imgcol, notecol = st.columns([3, 2])
        # id=notecol.text_input('id', row[1])
        id=notecol.text_input('کد محصول', row[1])
        note=notecol.text_area('اسم محصول', row[3])
        if row[2]:
            img=row[2]
            imgcol.image(row[2])

            

        
            
            
if selected == "تماس با ما":
    col1,col2 = st.columns(2)
    with col1:
        st.image("https://pvcahmad.vercel.app/ahmad.jpg")
    with col2:
        st.write("احمد ژرف")
        st.text(" شماره تماس : 09172114362 ")
        st.write("من از سال 1374 شروع به فعالیت کردم و سابقه کار تو حوزه طراحی و اجرای نصب پی وی سی با طرح های مختلف در سر تا سر جزیره قشم فعالیت میکنم و در خدمت شما مردم هستم برای اجرای نصب پی وی سی با من تماس بگیرید .")
            
    


st.write("---")

st.markdown("[ طراح و برنامه نویس : عبدالله چلاسی ](https://abdollah-chelasi.hf.space)")
            
    

st.markdown("""
<style> 
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
""",unsafe_allow_html=True)

Please check the code where the problem is

I think sqlite3 in the first row

import streamlit as st, sqlite3

Can you send me the code?

import streamlit as sqlite3 ,st

from streamlit_option_menu import option_menu

con=sqlite3.connect(‘abdollah.db’,check_same_thread=False)

cur=con.cursor()

cur.execute(‘CREATE TABLE IF NOT EXISTS pics(id TEXT, img BLOB, note TEXT)’)

I have done this before, I uploaded the file again, it has been deleted, please check the code and fix it for me

I have done this before, I uploaded the file again, it has been deleted, please check the code and fix it for me

Hi @Abdollah_Chelasi, the problem is that the files on Streamlit Cloud are not persistent, since the underlying instance that they are running on will get replaced occasionally. So, unfortunately, that doesn’t play well with sqlite. There are theoretically ways to get around this, if you can back up and restore your abdollah.db file to some 3rd party file host (e.g. S3), but I would recommend either:

  1. Run your app on a server that you have control over, so you can be sure that the files you create and modify will not be overwritten
  2. Use an external database, rather than a file-based sqlite database – you can see some examples here Connect to data sources - Streamlit Docs. Personally I have had good success with supabase and deta, which are both pretty simple to use, and work well for personal projects.

We are working on a built-in database for Streamlit which should make this problem much easier – see The next frontier for Streamlit for more.

1 Like

Please make a todo app with supabase and data and send it to me

Try change

>>> import streamlit as sqlite3, st
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'st'

to

>>> import streamlit as st
>>> import sqlite3

Hi @Abdollah_Chelasi,

Please refrain from asking other community members to build your app. We’d love to help you build it! But asking others to write your app takes away all the fun :slightly_smiling_face:

1 Like

I did this, but the file was deleted after a few hours
Please help, where is the problem with my codes?

My problem is that when I put the todo app on github and deployed it to the site and then added the todo app file, it was deleted after a few hours. Please help me, what should I do?

Before I deployed, I added a todo app file, then I put it on github and deployed it on the site. When I deleted the file that I added on the site, it came back after a few hours, which means it is not saved in the database.

Please guide me if there is a problem with these codes

import streamlit as st
import sqlite3
from streamlit_option_menu import option_menu

con=sqlite3.connect(‘picscols.db’,check_same_thread=False)
cur=con.cursor()
cur.execute(‘CREATE TABLE IF NOT EXISTS pics(id TEXT, img BLOB, note TEXT)’)

st.set_page_config(page_title=“خدمات PVC - رمکان”, page_icon=“https://namapoush.ir/wp-content/uploads/2021/06/WhatsApp-Image-2021-06-05-at-12.42.50.jpeg”)

selected = option_menu (
menu_title=None,
options=[“تماس با ما”,“ورود ادمین”,“صفحه اصلی”],
icons=[“house”,“book”, “envelope”],
menu_icon=“cast”,
default_index=2,
orientation=“horizontal”,
styles={

    "nav-link":{
        'font-family': 'Courier New' 'Courier' 'monospace'
    },
    
}

)

with st.expander(“خدمات PVC - رمکان”,expanded=True):

col1,col2=st.columns(2)

with col1:
    st.write("خدمات و اجرای نصب pvc با طرح های مختلف - در سر تا سر جزیره قشم")

with col2: 

  st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQgD3vXk45UtxrEbUektF9sAtgXPr8XPKk_7w&usqp=CAU")

with open(‘c.css’) as f:

st.markdown(f’{f.read()}’ ,unsafe_allow_html=True)

st.markdown(“”"
@import url(‘https://fonts.googleapis.com/css2?family=Lalezar&display=swap’);
.css-10trblm.e16nr0p30{
font-family: ‘Lalezar’, cursive;

padding: 3px;
text-align: center;
text-shadow: black 2px 2px 17px;
color: rgb(57, 60, 100);

}
.block-container{
direction: rtl;
}
/* BTN BALA */
.e1fb0mya1.css-fblp2m.ex0cdmw0{
border-style: groove;
border-color: black;
background: linear-gradient(rgb(40, 110, 114),rgb(77, 77, 192),rgb(75, 25, 25));
}
.e1fb0mya1.css-fblp2m.ex0cdmw0:hover{

background: linear-gradient(rgb(10, 243, 255),rgb(37, 37, 252),rgb(255, 34, 34));

}
/* صفحه بالا /
.css-1avcm0n.e8zbici2{
background: linear-gradient(rgb(7, 17, 9),rgb(44, 44, 83),rgb(5, 58, 59));
}
/
PVC /
.css-10trblm.e16nr0p30{
color: aliceblue;
background: linear-gradient(rgb(4, 48, 61),rgb(10, 10, 58),rgb(55, 212, 214));
border-radius: 5px;
width: 100%;
}
/
Home */
.main.css-k1vhr4.egzxvld3{
background: linear-gradient(rgb(5, 42, 44),rgb(5, 5, 19),rgb(14, 8, 8));
}
.css-8ojfln.e1wqxbhn1{
font-family: ‘Lalezar’, cursive;

}
/* cALL */
.css-183lzff.eyqtai90{
font-family: ‘Lalezar’, cursive;
text-shadow: rgb(87, 61, 7) 1px 1px 9px;
color: rgb(238, 209, 45);
}
.css-1fv8s86.e16nr0p34 p{
font-family: ‘Lalezar’, cursive;
color: rgb(57, 194, 123);
text-shadow: rgb(41, 194, 21) 1px 1px 9px;
}
.css-5uatcg.edgvbvh5{
font-family: ‘Lalezar’, cursive;
}
.css-1v0mbdj.etr89bj1 img{
border-style: groove;
border-color: rgb(8, 55, 99);
width: 200px;
height: 150px;
border-radius: 13px;
box-shadow: rgb(0, 0, 0) 1px 1px 7px;

}
.css-1fv8s86.e16nr0p34 a{
font-family: ‘Lalezar’, cursive;
text-align: center;
text-decoration: none;
padding: 5px;
border-radius: 11px;
background: linear-gradient(rgb(14, 47, 49),rgb(5, 43, 75),rgb(10, 8, 14));
}
.css-1fv8s86.e16nr0p34 a:hover{
color: aliceblue;
border-style: groove;
border-color: rgb(22, 22, 43);
background: linear-gradient(rgb(47, 146, 151),rgb(57, 110, 153),rgb(10, 8, 14));
}
/* Label /
.css-1yy6isu.e16nr0p34 p{
font-family: ‘Lalezar’, cursive;
color: rgb(51, 206, 46);
text-shadow: rgb(161, 245, 65) 1px 1px 9px;
}
/
Navbar */
.css-6qob1r.e1fqkh3o3{
background: linear-gradient(rgb(5, 5, 19),rgb(5, 42, 44),rgb(14, 8, 8));
}
“”" ,unsafe_allow_html=True)

if selected == “ورود ادمین”:

username = st.text_input(label="نام کاربری",placeholder="Username")
password = st.text_input(label="پسورد",placeholder="password",type="password")
btnLogin = st.button("ورود")

if username == "admin" and password == "admin":
	st.success("خوش آمدی ادمین")
	selected = option_menu(options=["پست های ادمین"],
    menu_title=""

    
    
    )
	

elif username or password == "admin":
	st.error("لطفا درست وارد کنید")

if selected == “پست های ادمین”:

if st.button('اضافه کردن محصول'):
    cur.execute('INSERT INTO pics(id, img, note) VALUES(?,?,?)', ('', '', ''))
    con.commit()

for row in cur.execute('SELECT rowid, id, img, note FROM pics ORDER BY id'):
    with st.form(f'ID-{row[0]}', clear_on_submit=True):
        imgcol, notecol = st.columns([3, 2])
        id=notecol.text_input('کد محصول', row[1])
        note=notecol.text_area('نام محصول', row[3])
        if row[2]:
            img=row[2]
            imgcol.image(row[2])
        file=imgcol.file_uploader('تصاویر', ['png', 'jpg', 'gif', 'bmp'])
        if file: 
            img=file.read()
        if notecol.form_submit_button('ذخیره محصول'):
            
            cur.execute(
                'UPDATE pics SET id=?, img=?, note=? WHERE id=?;', 
                (id, img, note, str(row[1]))
                )
            con.commit()
            st.experimental_rerun()
        if notecol.form_submit_button("حذف محصول"):
            cur.execute(f'''DELETE FROM pics WHERE rowid="{row[0]}";''')
            con.commit()
            st.experimental_rerun()

if selected == “صفحه اصلی”:

 for row in cur.execute('SELECT rowid, id, img, note FROM pics ORDER BY id'):
    # with st.form(f'ID-{row[0]}', clear_on_submit=True):
    st.write("---")
    imgcol, notecol = st.columns([3, 2])
    # id=notecol.text_input('id', row[1])
    id=notecol.text_input('کد محصول', row[1])
    note=notecol.text_area('اسم محصول', row[3])
    if row[2]:
        img=row[2]
        imgcol.image(row[2])

if selected == “تماس با ما”:
col1,col2 = st.columns(2)
with col1:
st.image(“https://pvcahmad.vercel.app/ahmad.jpg”)
with col2:
st.write(“احمد ژرف”)
st.text(" شماره تماس : 09172114362 ")
st.write(“من از سال 1374 شروع به فعالیت کردم و سابقه کار تو حوزه طراحی و اجرای نصب پی وی سی با طرح های مختلف در سر تا سر جزیره قشم فعالیت میکنم و در خدمت شما مردم هستم برای اجرای نصب پی وی سی با من تماس بگیرید .”)

st.write(“—”)

st.markdown(" طراح و برنامه نویس : عبدالله چلاسی ")

st.markdown(“”"

#MainMenu {visibility: hidden;} footer {visibility: hidden;}

“”",unsafe_allow_html=True)Preformatted text

https://share.streamlit.io/
This address does not open in Iran, please fix the problem so that I can enter without a filter breaker

Hi @Abdollah_Chelasi, unfortunately, that sounds like a network issue, which we don’t have control over

Can you also clarify what you mean by “I did this, but the file was deleted after a few hours”? Which file was deleted, and how did you add the file?

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